二维码

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值