二维码生成

2018-03-30  本文已影响0人  听雨哭的声音_7fc5

#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];

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

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

    [self.view addSubview: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 = [QRCodeGenerator qrImageForString:textTf.text    imageSize:imagerView.bounds.size.width];

    imagerView.image = image;

}

上一篇 下一篇

猜你喜欢

热点阅读