美文网首页
二维码生成

二维码生成

作者: 济公活佛是小松鼠 | 来源:发表于2018-03-30 14:18 被阅读0次

    #import "ViewController.h"

    #import "QRCodeGenerator.h"

    @interface ViewController ()

    {

    //创建文本对象

        UITextField*textTf;

    //创建图片对象

        UIImageView*imagerView;

     }

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

        btn.frame=CGRectMake(120,200,160,40);

        btn.backgroundColor = [UIColor redColor];

        [btnsetTitle:@"二维码生成" forState:UIControlStateNormal];

        [btnaddTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];

        [self.viewaddSubview:btn];

        textTf = [[UITextField alloc]initWithFrame:CGRectMake(100, 90, 160, 44)];

        textTf.backgroundColor = [UIColor yellowColor];

        [self.view addSubview:textTf];

        imagerView = [[UIImageView  alloc]initWithFrame:CGRectMake(20, 300, 300, 200)];

        imagerView.backgroundColor = [UIColor lightGrayColor];

        [self.view addSubview:imagerView];

    }

    //实现二维码关键响应方法

    -(void)click{

       //关键是这一行代码(生成二维码)

      UIImage*image = [QRCodeGeneratorqrImageForString:textTf.text    imageSize:imagerView.bounds.size.width];

      imagerView.image= image;

    }

    相关文章

      网友评论

          本文标题:二维码生成

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