IOS开发中生成图片验证码绘图实例代码

来源:爱站网时间:2021-01-15编辑:网友分享
验证码在开发中已经非常普及了,而验证码有时候会被定义为恶意信息,那么IOS开发中生成图片验证码绘图实例代码,大家都清楚吗?今天爱站技术频频就和大家分享,也给大家做个参考。

验证码在开发中已经非常普及了,而验证码有时候会被定义为恶意信息,那么IOS开发中生成图片验证码绘图实例代码,大家都清楚吗?今天爱站技术频频就和大家分享,也给大家做个参考。

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

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 
@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 

github下载地址

上述是爱站技术频道小编带给大家的IOS开发中生成图片验证码绘图实例代码,而这些都是程序员需要谨记的,希望能对你学习这方面知识有所帮助。

上一篇:使用iOS推送时警告错误怎么办

下一篇:IOS开发中重定向302跳转的详细方法

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载