iOS第三方框架二維碼生成與掃描

本文實(shí)例為大家分享了iOS第三方二維碼生成與掃描的具體代碼,供大家參考,具體內(nèi)容如下

成都創(chuàng)新互聯(lián)公司網(wǎng)絡(luò)公司擁有十年的成都網(wǎng)站開發(fā)建設(shè)經(jīng)驗(yàn),近千家客戶的共同信賴。提供成都做網(wǎng)站、網(wǎng)站制作、網(wǎng)站開發(fā)、網(wǎng)站定制、友情鏈接、建網(wǎng)站、網(wǎng)站搭建、成都響應(yīng)式網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)師打造企業(yè)風(fēng)格,提供周到的售前咨詢和貼心的售后服務(wù)

導(dǎo)入第三方框架libqrencode(生成二維碼)和ZBarSDK(二維碼掃描)

導(dǎo)入頭文件

#import "QRCodeGenerator.h"
#import "ZBarSDK.h"

創(chuàng)建兩個(gè)按鈕點(diǎn)擊事件
點(diǎn)擊按鈕一實(shí)現(xiàn)生成二維碼

- (IBAction)erWeiMaBtn1:(id)sender {
// 設(shè)置圖片框存放二維碼
  UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake((self.view.frame.size.width - 200)/2, 100, 200, 200)];
// 展示到主視圖
  [self.view addSubview:self.imgView];
// 利用第三方方法實(shí)現(xiàn)自己想要的二維碼  
  imgView.image = [QRCodeGenerator qrImageForString:@"傻子" imageSize:self.imgView.frame.size.width];
}

點(diǎn)擊按鈕二實(shí)現(xiàn)掃描二維碼

- (IBAction)erWeiMaBtn1:(id)sender {
  //設(shè)置文本域(設(shè)置為全局)
  _textView = [[UITextView alloc]initWithFrame:CGRectMake((self.view.frame.size.width-300)/2, 430, 300, 300) textContainer:nil];
  //設(shè)置背景顏色
  _textView.backgroundColor = [UIColor blueColor];
  //添加到主視圖
  [self.view addSubview:self.textView];

  ZBarReaderViewController *reader = [[ZBarReaderViewController alloc] init];
  reader.readerDelegate =self;
  //隱藏底部控制按鈕
  reader.showsZBarControls =YES;
  //設(shè)置自己定義的界面
  //reader.cameraOverlayView = someView;(這個(gè)視圖可以自己定義,當(dāng)然你也可以通過[reader.view addSubview:someView]的方式添加蒙版視圖,這樣可以做出自己想要的視圖效果)
  //設(shè)置識(shí)別范圍(這里的4個(gè)參數(shù)都是視圖比例~~不要搞錯(cuò)奧(距離左邊的比例,距離上邊的比例,識(shí)別寬度的比例,識(shí)別高度的比例))
  //reader.scanCrop =CGRectMake(0,0, 1,1);
  //設(shè)置識(shí)別的參數(shù)
  ZBarImageScanner *scanner = reader.scanner;
  [scanner setSymbology:ZBAR_I25  //這個(gè)參數(shù)和to:后面的參數(shù)配合確定了識(shí)別的編碼范圍,根據(jù)需求調(diào)整,可以提高識(shí)別速度。
          config:ZBAR_CFG_ENABLE
            to:0];
  [self presentViewController:reader animated:YES completion:nil];
}
//下面是委托方法
- (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info
{
  id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
  ZBarSymbol *symbol =nil;
  for(symbol in results)
    break;
  NSLog(@"%@",symbol.data);//打印識(shí)別的數(shù)據(jù)
  //設(shè)置內(nèi)容
  _textView.text = symbol.data;
  //
  [reader dismissModalViewControllerAnimated:YES];
}

注意:在info.plist中填入可用相機(jī)掃描的白名單!

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

當(dāng)前文章:iOS第三方框架二維碼生成與掃描
文章位置:http://www.muchs.cn/article48/pgdpep.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站全網(wǎng)營(yíng)銷推廣、網(wǎng)站營(yíng)銷、網(wǎng)站維護(hù)、網(wǎng)站設(shè)計(jì)公司網(wǎng)站設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

微信小程序開發(fā)