IOS SGQRCode 生成二维码

1. 用cocodata导入  pod 'SGQRCode'


#import "ViewController.h"

#import

@interface ViewController ()<SGQRCodeScanManagerDelegate>

{

    

    NSMutableString *str;

}

@property (weak, nonatomic) IBOutlet UILabel *label;

@property (weak, nonatomic) IBOutlet UITextField *textfil;

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


@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

}

- (IBAction)button:(id)sender {

    SGQRCodeScanManager *scanManager = [SGQRCodeScanManager sharedManager];

    NSArray *arr = @[AVMetadataObjectTypeQRCode, AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeCode128Code];

    // AVCaptureSessionPreset1920x1080 推荐使用,对于小型的二维码读取率较高

    [scanManager setupSessionPreset:AVCaptureSessionPreset1920x1080 metadataObjectTypes:arr currentController:self];

    scanManager.delegate = self;

}

/// 二维码扫描获取数据的回调方法

- (void)QRCodeScanManager:(SGQRCodeScanManager *)scanManager didOutputMetadataObjects:(NSArray *)metadataObjects

{

    for (int i=0;i < metadataObjects.count;i++)

    {

        str = [NSMutableString new];

        [str appendString:metadataObjects[i]];

    }

    self.label.text = str;


}



- (IBAction)shengchegn:(id)sender {

    // 二维码


  //self.imageview.image = [SGQRCodeGenerateManager generateWithDefaultQRCodeData:self.textfil.text imageViewWidth:100];

// 带有图片的二维码

    self.imageview.image= [SGQRCodeGenerateManager generateWithLogoQRCodeData:self.textfil.text logoImageName:@"bonsai" logoScaleToSuperView:0.3];

// 彩色的二维码

    //self.imageview.image = [SGQRCodeGenerateManager generateWithColorQRCodeData:@"http://music.163.com/#/m/song?id=516076896" backgroundColor:[CIColor colorWithRed:1 green:0.1 blue:0.8] mainColor:[CIColor colorWithRed:0.3 green:0.5 blue:0.2]];


}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event

{

    [self.view endEditing:YES];

}


@end


你可能感兴趣的:(iOS开发)