美文网首页
生成简单的二维码

生成简单的二维码

作者: 其实你懂De | 来源:发表于2016-08-22 08:35 被阅读58次

今天给大家讲讲成简单的二维码。

- (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 {
    // 创建过滤器
    CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
    //恢复默认
    [filter setDefaults];
    //给过滤器添加数据
    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];
    
    
    
    
    
}


之后用手机一扫描就OKle 这是生成简单的二维码,代码很少,希望大家自己研究会了!

20FD0E78-7DAB-4BB8-BEE1-F5531814C76E.png

相关文章

网友评论

      本文标题:生成简单的二维码

      本文链接:https://www.haomeiwen.com/subject/jpbwsttx.html