登录注册时用的验证码效果图

ViewDidload调用即可
_pooCodeView = [[PooCodeView alloc] initWithFrame:CGRectMake(50, 100, 82, 32)];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
[_pooCodeView addGestureRecognizer:tap];
[self.view addSubview:_pooCodeView];
#import <UIKit/UIKit.h>
@interface PooCodeView : UIView
@property (nonatomic, retain) NSArray *changeArray;
@property (nonatomic, retain) NSMutableString *changeString;
@property (nonatomic, retain) UILabel *codeLabel;
-(void)changeCode;
@end
#import "PooCodeView.h"
@implementation PooCodeView
@synthesize changeArray = _changeArray;
@synthesize changeString = _changeString;
@synthesize codeLabel = _codeLabel;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
// self.layer.cornerRadius = 5.0;
// self.layer.masksToBounds = YES;
float red = arc4random() % 100 / 100.0;
float green = arc4random() % 100 / 100.0;
float blue = arc4random() % 100 / 100.0;
UIColor *color = [UIColor colorWithRed:red green:green blue:blue alpha:0.2];
self.backgroundColor = color;
[self change];
}
return self;
}
//-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
//{
// [self change];
// [self setNeedsDisplay];
//}
-(void)changeCode{
[self change];
[self setNeedsDisplay];
}
- (void)change
{
self.changeArray = [[NSArray alloc] initWithObjects:@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z",@"a",@"b",@"c",@"d",@"e",@"f",@"g",@"h",@"i",@"j",@"k",@"l",@"m",@"n",@"o",@"p",@"q",@"r",@"s",@"t",@"u",@"v",@"w",@"x",@"y",@"z",nil];
NSMutableString *getStr = [[NSMutableString alloc] initWithCapacity:5];
self.changeString = [[NSMutableString alloc] initWithCapacity:6];
for(NSInteger i = 0; i < 4; i++)
{
NSInteger index = arc4random() % ([self.changeArray count] - 1);
getStr = [self.changeArray objectAtIndex:index];
self.changeString = (NSMutableString *)[self.changeString stringByAppendingString:getStr];
}
}
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
float red = arc4random() % 100 / 100.0;
float green = arc4random() % 100 / 100.0;
float blue = arc4random() % 100 / 100.0;
UIColor *color = [UIColor colorWithRed:red green:green blue:blue alpha:0.5];
[self setBackgroundColor:color];
NSString *text = [NSString stringWithFormat:@"%@",self.changeString];
CGSize cSize = [@"S" sizeWithFont:[UIFont systemFontOfSize:20]];
int width = rect.size.width / text.length - cSize.width;
int height = rect.size.height - cSize.height;
CGPoint point;
float pX, pY;
for (int i = 0; i < text.length; i++)
{
pX = arc4random() % width + rect.size.width / text.length * i;
pY = arc4random() % height;
point = CGPointMake(pX, pY);
unichar c = [text characterAtIndex:i];
NSString *textC = [NSString stringWithFormat:@"%C", c];
[textC drawAtPoint:point withFont:[UIFont systemFontOfSize:20]];
}
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 1.0);
for(int cout = 0; cout < 10; cout++)
{
red = arc4random() % 100 / 100.0;
green = arc4random() % 100 / 100.0;
blue = arc4random() % 100 / 100.0;
color = [UIColor colorWithRed:red green:green blue:blue alpha:0.2];
CGContextSetStrokeColorWithColor(context, [color CGColor]);
pX = arc4random() % (int)rect.size.width;
pY = arc4random() % (int)rect.size.height;
CGContextMoveToPoint(context, pX, pY);
pX = arc4random() % (int)rect.size.width;
pY = arc4random() % (int)rect.size.height;
CGContextAddLineToPoint(context, pX, pY);
CGContextStrokePath(context);
}
}
@end
github下载地址
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
相关文章:
mc皮肤壁纸制作器,苹果平板怎么设置自己想要的壁纸我的世界?
如何快速重置建站主机并恢复默认配置?
平台云上自主建站:模板化设计与智能工具打造高效网站
建站之星如何保障用户数据免受黑客入侵?
如何解决ASP生成WAP建站中文乱码问题?
如何打造高效商业网站?建站目的决定转化率
建站上传速度慢?如何优化加速网站加载效率?
如何选择高效响应式自助建站源码系统?
建站之星云端配置指南:模板选择与SEO优化一键生成
较简单的网站制作软件有哪些,手机版网页制作用什么软件?
如何快速选择适合个人网站的云服务器配置?
专业网站设计制作公司,如何制作一个企业网站,建设网站的基本步骤有哪些?
香港服务器网站推广:SEO优化与外贸独立站搭建策略
江苏网站制作公司有哪些,江苏书法考级官方网站?
,网站推广常用方法?
宝塔建站后网页无法访问如何解决?
高防网站服务器:DDoS防御与BGP线路的AI智能防护方案
建站之星logo尺寸如何设置最合适?
,sp开头的版面叫什么?
香港服务器网站搭建教程-电商部署、配置优化与安全稳定指南
常州企业网站制作公司,全国继续教育网怎么登录?
简历在线制作网站免费,免费下载个人简历的网站是哪些?
台州网站建设制作公司,浙江手机无犯罪记录证明怎么开?
已有域名和空间,如何快速搭建网站?
如何选择CMS系统实现快速建站与SEO优化?
大连网站设计制作招聘信息,大连投诉网站有哪些?
如何在IIS中新建站点并配置端口与IP地址?
rsync同步时出现rsync: failed to set times on “xxxx”: Operation not permitted
,有什么在线背英语单词效率比较高的网站?
如何在云指建站中生成FTP站点?
PHP 500报错的快速解决方法
南平网站制作公司,2025年南平市事业单位报名时间?
香港服务器网站卡顿?如何解决网络延迟与负载问题?
如何制作算命网站,怎么注册算命网站?
如何快速查询域名建站关键信息?
图册素材网站设计制作软件,图册的导出方式有几种?
网页设计网站制作软件,microsoft office哪个可以创建网页?
制作营销网站公司,淘特是干什么用的?
盐城做公司网站,江苏电子版退休证办理流程?
建站主机选购指南:核心配置优化与品牌推荐方案
如何用AWS免费套餐快速搭建高效网站?
c# 在ASP.NET Core中管理和取消后台任务
整蛊网站制作软件,手机不停的收到各种网站的验证码短信,是手机病毒还是人为恶搞?有这种手机病毒吗?
Thinkphp 中 distinct 的用法解析
如何挑选高效建站主机与优质域名?
建站之星后台密码遗忘?如何快速找回?
儿童网站界面设计图片,中国少年儿童教育网站-怎么去注册?
Swift中循环语句中的转移语句 break 和 continue
海南网站制作公司有哪些,海口网是哪家的?
如何注册花生壳免费域名并搭建个人网站?
*请认真填写需求信息,我们会在24小时内与您取得联系。