1. 程式人生 > >iOS二維生成

iOS二維生成

nat data implement 默認 default fork weak .com ont

#import "ViewController.h"

@interface ViewController ()

// 用於顯示生成二維碼圖片的 imageView

@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation ViewController

// 點擊生成二維碼

- (IBAction)click {

//創建濾鏡

CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];

//設置默認值

[filter setDefaults];

//設置內容

[filter setValue:[@"https://www.baidu.com" dataUsingEncoding:NSUTF8StringEncoding] forKey:@"inputMessage"];

//生成圖片

CIImage *image = [filter outputImage];

//放大圖片

image = [image imageByApplyingTransform:CGAffineTransformMakeScale(8, 8)];

//顯示二維碼圖片

self.imageView.image = [UIImage imageWithCIImage:image];

}

@end

iOS二維生成