生成二维码:
1. 下载libqrencode三方后, 拉入工程
2. 在头文件引用 #import “QRCodeGenerator.h”
3. 效果图:
4.
代码:
// 文本框
UITextField *textfield = [[UITextField alloc] initWithFrame:CGRectMake(20, 20, 200, 50)];
[self.view addSubview:textfield];
textfield.backgroundColor = [UIColor grayColor];
textfield.placeholder = @"请输入文字";
textfield.tag = 1;
// 按钮
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(250, 20, 50, 50);
[self.view addSubview:button];
button.backgroundColor = [UIColor orangeColor];
[button setTitle:@"生成" forState:UIControlStateNormal];
[button addTarget:self action:@selector(QRCode) forControlEvents:UIControlEventTouchUpInside];
方法:
- (void)QRCode {
UITextField *textfield = [self.view viewWithTag:1];
UIImage *image = [QRCodeGenerator qrImageForString:textfield.text imageSize:200];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 70, 200, 200)];
imageView.center = self.view.center;
imageView.image = image;
[self.view addSubview:imageView];
}
如果在编译中爆出c99错误, 可以在#import “QRCodeGenerator.h”文件中, 引用:
原文:http://www.cnblogs.com/guominghao/p/5041948.html