二维码扫描代码
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
[alertView show];
//判断是否包含 头'ssid:' NSString *ssid =@"ssid+:[^\\s]*";; NSPredicate *ssidPre = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",ssid];
symbolStr = [NSString stringWithFormat:@"ssid: %@ \n password:%@",
[arrInfoHead objectAtIndex:1],[arrInfoFoot objectAtIndex:1]];
UIPasteboard *pasteboard=[UIPasteboard generalPasteboard];
#import <UIKit/UIKit.h> #import "ZBarSDK.h"
@interface yxpQrCode :UIViewController @end
// // 实现文件 // TestProject // #import "yxpQrCode.h"
#define SCANVIEW_EdgeTop 40.0 #define SCANVIEW_EdgeLeft 50.0
//然后,可以使用如下代码来把一个字符串放置到 剪贴板上:
pasteboard.string = [arrInfoFoot objectAtIndex:1];
}
}
//二维码的扫描区域 - (void)setScanView {
_scanView=[[UIView alloc]initWithFrame:CGRectMake(0,0,VIEW_WIDTH,VIEW_HE IGHT-64)];
self.title=@"扫描二维码";
//初始化扫描界面 [self setScanView];
_readerView= [[ZBarReaderView alloc]init]; _readerView.frame =CGRectMake(0,64,VIEW_WIDTH, VIEW_HEIGHT -64); _readerView.tracksSymbols=NO; _readerView.readerDelegate =self; [_readerView addSubview:_scanView]; //关闭闪光灯 _readerView.torchMode =0;
#define TINTCOLOR_ALPHA 0.2 //浅色透明度 #define DARKCOLOR_ALPHA 0.5 //深色透明度
@interfaceyxpQrCode ()<ZBarReaderViewDelegate> {
UIView *_QrCodeline; NSTimer *_timer;
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) { // Custom initialization
} return self; }
- (void)viewDidLoad {
[superviewDidLoad];
[self.view addSubview:_readerView];
//扫描区域 //readerView.scanCrop =
[_readerView start];
[self createTimer];
} #pragma mark -- ZBarReaderViewDelegate -(void)readerView:(ZBarReaderView *)readerView didReadSymbols:(ZBarSymbolSet *)symbols fromImage:(UIImage *)image {
//判断是否包含 头'http:' NSString *regex =@"http+:[^\\s]*"; NSPredicate *predicate = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@",regex];
UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@""message:symbolStr delegate:nil cancelButtonTitle:@"取消"otherButtonTitles:nil];
/******************中间扫描区域 ****************************/
Байду номын сангаас
UIImageView *scanCropView=[[UIImageView alloc]initWithFrame:CGRectMake(SCANVIEW_EdgeLeft,SCAN VIEW_EdgeTop,VIEW_WIDTH-2*SCANVIEW_EdgeLeft,VIEW_ WIDTH-2*SCANVIEW_EdgeLeft)];
//左侧的view UIView *leftView = [[UIView alloc]initWithFrame:CGRectMake(0,SCANVIEW_EdgeTop,SCA NVIEW_EdgeLeft,VIEW_WIDTH-2*SCANVIEW_EdgeLeft)]; leftView.alpha =TINTCOLOR_ALPHA; leftView.backgroundColor = [UIColor blackColor]; [_scanView addSubview:leftView];
const zbar_symbol_t *symbol =zbar_symbol_set_first_symbol(symbols.zbarSymbolSet);
NSString *symbolStr = [NSString stringWithUTF8String:zbar_symbol_get_data(symbol)];
NSArray * arrInfoHead = [[arr objectAtIndex:0]componentsSeparatedByString:@":"];
NSArray * arrInfoFoot = [[arr objectAtIndex:1]componentsSeparatedByString:@":"];
if ([predicate evaluateWithObject:symbolStr]) {
} elseif([ssidPre evaluateWithObject:symbolStr]){
NSArray *arr = [symbolStr componentsSeparatedByString:@";"];
//底部view UIView *downView = [[UIView alloc]initWithFrame:CGRectMake(0,VIEW_WIDTH-2*SCANVIE W_EdgeLeft+SCANVIEW_EdgeTop,VIEW_WIDTH,VIEW_HEIG HT-(VIEW_WIDTH-2*SCANVIEW_EdgeLeft+SCANVIEW_EdgeT op)-64)]; //downView.alpha = TINTCOLOR_ALPHA;
//右侧的view UIView *rightView = [[UIViewalloc]initWithFrame:CGRectMake(VIEW_WIDTH-SCA NVIEW_EdgeLeft,SCANVIEW_EdgeTop,SCANVIEW_EdgeLeft, VIEW_WIDTH-2*SCANVIEW_EdgeLeft)]; rightView.alpha =TINTCOLOR_ALPHA; rightView.backgroundColor = [UIColorblackColor]; [_scanView addSubview:rightView];
_scanView.backgroundColor=[UIColor clearColor];
//最上部view UIView* upView = [[UIView lloc]initWithFrame:CGRectMake(0,0,VIEW_WIDTH,SCANVIE W_EdgeTop)]; upView.alpha =TINTCOLOR_ALPHA; upView.backgroundColor = [UIColor blackColor]; [_scanView addSubview:upView];
//scanCropView.image=[UIImage imageNamed:@""];
scanCropView.layer.borderColor=[UIColor getThemeColor].CGColor;
scanCropView.layer.borderWidth=2.0;
scanCropView.backgroundColor=[UIColor clearColor]; [_scanView addSubview:scanCropView];
forState:UIControlStateNormal]; [openButton
setTitleColor:[UIColorwhiteColor]forState:UIControlStateNor mal];
UIView *darkView = [[UIViewalloc]initWithFrame:CGRectMake(0, downView.frame.size.height-100.0,VIEW_WIDTH,100.0)];
darkView.backgroundColor = [[UIColorblackColor] colorWithAlphaComponent:DARKCOLOR _ALPHA];
downView.backgroundColor = [[UIColorblackColor]colorWithAlphaComponent:TINTCOLOR_ ALPHA];
[_scanViewaddSubview:downView];
//用于说明的label UILabel *labIntroudction= [[UILabelalloc]init]; labIntroudction.backgroundColor = [UIColorclearColor]; labIntroudction.frame=CGRectMake(0,5,VIEW_WIDTH,20 ); labIntroudction.numberOfLines=1; labIntroudction.font=[UIFontsystemFontOfSize:15.0]; labIntroudction.textAlignment=NSTextAlignmentCenter; labIntroudction.textColor=[UIColorwhiteColor]; labIntroudction.text=@"将二维码对准方框,即可自动扫 描"; [downViewaddSubview:labIntroudction];
[downViewaddSubview:darkView];
//用于开关灯操作的button UIButton *openButton=[[UIButtonalloc]initWithFrame:CGRectMake(1 0,20,300.0, 40.0)]; [openButtonsetTitle:@"开启闪光灯"
//设置扫描画面 UIView *_scanView; ZBarReaderView *_readerView; }
@end
@implementation yxpQrCode
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil {
//判断是否包含 头'ssid:' NSString *ssid =@"ssid+:[^\\s]*";; NSPredicate *ssidPre = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",ssid];
symbolStr = [NSString stringWithFormat:@"ssid: %@ \n password:%@",
[arrInfoHead objectAtIndex:1],[arrInfoFoot objectAtIndex:1]];
UIPasteboard *pasteboard=[UIPasteboard generalPasteboard];
#import <UIKit/UIKit.h> #import "ZBarSDK.h"
@interface yxpQrCode :UIViewController @end
// // 实现文件 // TestProject // #import "yxpQrCode.h"
#define SCANVIEW_EdgeTop 40.0 #define SCANVIEW_EdgeLeft 50.0
//然后,可以使用如下代码来把一个字符串放置到 剪贴板上:
pasteboard.string = [arrInfoFoot objectAtIndex:1];
}
}
//二维码的扫描区域 - (void)setScanView {
_scanView=[[UIView alloc]initWithFrame:CGRectMake(0,0,VIEW_WIDTH,VIEW_HE IGHT-64)];
self.title=@"扫描二维码";
//初始化扫描界面 [self setScanView];
_readerView= [[ZBarReaderView alloc]init]; _readerView.frame =CGRectMake(0,64,VIEW_WIDTH, VIEW_HEIGHT -64); _readerView.tracksSymbols=NO; _readerView.readerDelegate =self; [_readerView addSubview:_scanView]; //关闭闪光灯 _readerView.torchMode =0;
#define TINTCOLOR_ALPHA 0.2 //浅色透明度 #define DARKCOLOR_ALPHA 0.5 //深色透明度
@interfaceyxpQrCode ()<ZBarReaderViewDelegate> {
UIView *_QrCodeline; NSTimer *_timer;
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) { // Custom initialization
} return self; }
- (void)viewDidLoad {
[superviewDidLoad];
[self.view addSubview:_readerView];
//扫描区域 //readerView.scanCrop =
[_readerView start];
[self createTimer];
} #pragma mark -- ZBarReaderViewDelegate -(void)readerView:(ZBarReaderView *)readerView didReadSymbols:(ZBarSymbolSet *)symbols fromImage:(UIImage *)image {
//判断是否包含 头'http:' NSString *regex =@"http+:[^\\s]*"; NSPredicate *predicate = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@",regex];
UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@""message:symbolStr delegate:nil cancelButtonTitle:@"取消"otherButtonTitles:nil];
/******************中间扫描区域 ****************************/
Байду номын сангаас
UIImageView *scanCropView=[[UIImageView alloc]initWithFrame:CGRectMake(SCANVIEW_EdgeLeft,SCAN VIEW_EdgeTop,VIEW_WIDTH-2*SCANVIEW_EdgeLeft,VIEW_ WIDTH-2*SCANVIEW_EdgeLeft)];
//左侧的view UIView *leftView = [[UIView alloc]initWithFrame:CGRectMake(0,SCANVIEW_EdgeTop,SCA NVIEW_EdgeLeft,VIEW_WIDTH-2*SCANVIEW_EdgeLeft)]; leftView.alpha =TINTCOLOR_ALPHA; leftView.backgroundColor = [UIColor blackColor]; [_scanView addSubview:leftView];
const zbar_symbol_t *symbol =zbar_symbol_set_first_symbol(symbols.zbarSymbolSet);
NSString *symbolStr = [NSString stringWithUTF8String:zbar_symbol_get_data(symbol)];
NSArray * arrInfoHead = [[arr objectAtIndex:0]componentsSeparatedByString:@":"];
NSArray * arrInfoFoot = [[arr objectAtIndex:1]componentsSeparatedByString:@":"];
if ([predicate evaluateWithObject:symbolStr]) {
} elseif([ssidPre evaluateWithObject:symbolStr]){
NSArray *arr = [symbolStr componentsSeparatedByString:@";"];
//底部view UIView *downView = [[UIView alloc]initWithFrame:CGRectMake(0,VIEW_WIDTH-2*SCANVIE W_EdgeLeft+SCANVIEW_EdgeTop,VIEW_WIDTH,VIEW_HEIG HT-(VIEW_WIDTH-2*SCANVIEW_EdgeLeft+SCANVIEW_EdgeT op)-64)]; //downView.alpha = TINTCOLOR_ALPHA;
//右侧的view UIView *rightView = [[UIViewalloc]initWithFrame:CGRectMake(VIEW_WIDTH-SCA NVIEW_EdgeLeft,SCANVIEW_EdgeTop,SCANVIEW_EdgeLeft, VIEW_WIDTH-2*SCANVIEW_EdgeLeft)]; rightView.alpha =TINTCOLOR_ALPHA; rightView.backgroundColor = [UIColorblackColor]; [_scanView addSubview:rightView];
_scanView.backgroundColor=[UIColor clearColor];
//最上部view UIView* upView = [[UIView lloc]initWithFrame:CGRectMake(0,0,VIEW_WIDTH,SCANVIE W_EdgeTop)]; upView.alpha =TINTCOLOR_ALPHA; upView.backgroundColor = [UIColor blackColor]; [_scanView addSubview:upView];
//scanCropView.image=[UIImage imageNamed:@""];
scanCropView.layer.borderColor=[UIColor getThemeColor].CGColor;
scanCropView.layer.borderWidth=2.0;
scanCropView.backgroundColor=[UIColor clearColor]; [_scanView addSubview:scanCropView];
forState:UIControlStateNormal]; [openButton
setTitleColor:[UIColorwhiteColor]forState:UIControlStateNor mal];
UIView *darkView = [[UIViewalloc]initWithFrame:CGRectMake(0, downView.frame.size.height-100.0,VIEW_WIDTH,100.0)];
darkView.backgroundColor = [[UIColorblackColor] colorWithAlphaComponent:DARKCOLOR _ALPHA];
downView.backgroundColor = [[UIColorblackColor]colorWithAlphaComponent:TINTCOLOR_ ALPHA];
[_scanViewaddSubview:downView];
//用于说明的label UILabel *labIntroudction= [[UILabelalloc]init]; labIntroudction.backgroundColor = [UIColorclearColor]; labIntroudction.frame=CGRectMake(0,5,VIEW_WIDTH,20 ); labIntroudction.numberOfLines=1; labIntroudction.font=[UIFontsystemFontOfSize:15.0]; labIntroudction.textAlignment=NSTextAlignmentCenter; labIntroudction.textColor=[UIColorwhiteColor]; labIntroudction.text=@"将二维码对准方框,即可自动扫 描"; [downViewaddSubview:labIntroudction];
[downViewaddSubview:darkView];
//用于开关灯操作的button UIButton *openButton=[[UIButtonalloc]initWithFrame:CGRectMake(1 0,20,300.0, 40.0)]; [openButtonsetTitle:@"开启闪光灯"
//设置扫描画面 UIView *_scanView; ZBarReaderView *_readerView; }
@end
@implementation yxpQrCode
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil {