今天給大家講講成簡(jiǎn)單的二維碼哭尝。
- (void)viewDidLoad {
[super viewDidLoad];
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(20, 400, 100, 50)];
[self.view addSubview:view];
view.backgroundColor = [UIColor redColor];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
// 創(chuàng)建過濾器
CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
//恢復(fù)默認(rèn)
[filter setDefaults];
//給過濾器添加數(shù)據(jù)
NSString *url = @"www.taobao.com";
NSData *data = [url dataUsingEncoding:NSUTF8StringEncoding];
[filter setValue:data forKey:@"inputMessage"];
// 獲取輸出的二維碼
CIImage *outputImage = [filter outputImage];
//顯示二維碼
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
[self.view addSubview:imageView];
imageView.image = [UIImage imageWithCIImage:outputImage];
}
之后用手機(jī)一掃描就OKle 這是生成簡(jiǎn)單的二維碼谬盐,代碼很少,希望大家自己研究會(huì)了劝枣!
20FD0E78-7DAB-4BB8-BEE1-F5531814C76E.png