iOS-二维码扫描界面(转)

网址学习:http://blog.csdn.net/linux_zkf/article/details/7724867     二维码扫描界面自定义

作者:朱克锋

邮箱:zhukefeng@iboxpay.com

转载请注明出处:http://blog.csdn.net/linux_zkf

 

这个简单的实例实在ZBarReaderViewController的view层上再加一层用于定义自己的界面

- (void)QRscan

{

    ZBarReaderViewController *reader = [ZBarReaderViewController new];

    reader.readerDelegate = self;

//非全屏

    reader.wantsFullScreenLayout = NO;

    //隐藏底部控制按钮

    reader.showsZBarControls = NO;    

//设置自己定义的界面

    [self setOverlayPickerView:reader];

    ZBarImageScanner *scanner = reader.scanner;

   [scanner setSymbology: ZBAR_I25

                   config: ZBAR_CFG_ENABLE

                       to: 0];

    [self presentModalViewController: reader

                            animated: YES];

    [reader release];

}

- (void)setOverlayPickerView:(ZBarReaderViewController *)reader

{

//清除原有控件

    for (UIView *temp in [reader.view subviews]) {        

        for (UIButton *button in [temp subviews]) {

            if ([button isKindOfClass:[UIButton class]]) {                

                [button removeFromSuperview];               

            }

        }        

        for (UIToolbar *toolbar in [temp subviews]) {               

            if ([toolbar isKindOfClass:[UIToolbar class]]) {                

                [toolbar setHidden:YES];

                [toolbar removeFromSuperview];

            }

        }

    }

    //画中间的基准线

    UIView* line = [[UIView alloc] initWithFrame:CGRectMake(40, 220, 240, 1)];

    line.backgroundColor = [UIColor redColor];

    [reader.view addSubview:line];

    [line release];   

//最上部view

    UIView* upView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 80)];

    upView.alpha = 0.3;

    upView.backgroundColor = [UIColor blackColor];

    [reader.view addSubview:upView];

    //用于说明的label

    UILabel * labIntroudction= [[UILabel alloc] init];

    labIntroudction.backgroundColor = [UIColor clearColor];

    labIntroudction.frame=CGRectMake(15, 20, 290, 50);

    labIntroudction.numberOfLines=2;   

    labIntroudction.textColor=[UIColor whiteColor];

    labIntroudction.text=@"将二维码图像置于矩形方框内,离手机摄像头10CM左右,系统会自动识别。";

    [upView addSubview:labIntroudction];

    [labIntroudction release];

    [upView release];    

//左侧的view

    UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 80, 20, 280)];

    leftView.alpha = 0.3;

    leftView.backgroundColor = [UIColor blackColor];

    [reader.view addSubview:leftView];

    [leftView release];

//右侧的view  

    UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(300, 80, 20, 280)];

    rightView.alpha = 0.3;

    rightView.backgroundColor = [UIColor blackColor];

    [reader.view addSubview:rightView];

    [rightView release];   

    //底部view

    UIView * downView = [[UIView alloc] initWithFrame:CGRectMake(0, 360, 320, 120)];

    downView.alpha = 0.3;

    downView.backgroundColor = [UIColor blackColor];

    [reader.view addSubview:downView];

    [downView release];           

    //用于取消操作的button

    UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];    

    cancelButton.alpha = 0.4;

    [cancelButton setFrame:CGRectMake(20, 390, 280, 40)]; 

    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];

    [cancelButton.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];

    [cancelButton addTarget:self action:@selector(dismissOverlayView:)forControlEvents:UIControlEventTouchUpInside];

    [reader.view addSubview:cancelButton];

}

//取消button方法

- (void)dismissOverlayView:(id)sender{ 

    [self dismissModalViewControllerAnimated: YES];

}

转载于:https://www.cnblogs.com/linxiu-0925/p/5434846.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值