码迷,mamicode.com
首页 > 其他好文 > 详细

关于二维码的简单使用

时间:2015-12-12 23:08:14      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:

生成二维码: 
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];
}

warning

如果在编译中爆出c99错误, 可以在#import “QRCodeGenerator.h”文件中, 引用:

import 

 

关于二维码的简单使用

标签:

原文地址:http://www.cnblogs.com/guominghao/p/5041948.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!