Flashlight lights or turns off events

Source: Internet
Author: User


Hint Label

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

Promptlabel.backgroundcolor = [Uicolor Clearcolor];

CGFloat promptlabelx = 0;

CGFloat promptlabely = Cgrectgetmaxy (scancontent_layer.frame) + 30;

CGFloat promptlabelw = self.frame.size.width;

CGFloat promptlabelh = 25;

Promptlabel.frame = CGRectMake (Promptlabelx, promptlabely, Promptlabelw, PROMPTLABELH);

Promptlabel.textalignment = Nstextalignmentcenter;

Promptlabel.font = [Uifont boldsystemfontofsize:13.0];

Promptlabel.textcolor = [[Uicolor whitecolor] colorwithalphacomponent:0.6];

Promptlabel.text = @ "The two-dimensional code/bar code into the box, you can automatically scan";

[Self Addsubview:promptlabel];

UIView *bottomview = [[UIView alloc] init];

Bottomview.frame = CGRectMake (0, self.frame.size.height-100, self.frame.size.width, 100);

BottomView.layer.backgroundColor = [RGB (Colorwithalphacomponent:scanborderoutsideviewalpha, +, +)]. Cgcolor;

[Self addsubview:bottomview];

_torchimageview = [[Uiimageview alloc] init];

_torchimageview.image = [UIImage imagenamed:@ "Torch"];

_torchimageview.frame = CGRectMake ((self.frame.size.width-40)/2, 6, 40, 44);

[Bottomview Addsubview:_torchimageview];

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

Torchlabel.backgroundcolor = [Uicolor Clearcolor];

Torchlabel.frame = CGRectMake (0, +, self.frame.size.width, 40);

Torchlabel.textalignment = Nstextalignmentcenter;

Torchlabel.font = [Uifont boldsystemfontofsize:14.0];

Torchlabel.textcolor = HEX (@ "#999999");

Torchlabel.text = @ "Flashlight";

[Bottomview Addsubview:torchlabel];

Add Flash button

UIButton *light_button = [[UIButton alloc] init];

Light_button.frame = Bottomview.bounds;

CGFloat Light_buttonx = 0;

CGFloat light_buttony = Cgrectgetmaxy (promptlabel.frame) + scancontent_x * 0.5;

CGFloat light_buttonw = self.frame.size.width;

CGFloat Light_buttonh = 25;

Light_button.frame = CGRectMake (Light_buttonx, Light_buttony, Light_buttonw, Light_buttonh);

[Light_button settitle:@ "Open the Light" forstate:uicontrolstatenormal];

[Light_button settitle:@ "Turn Off the Lights" forstate:uicontrolstateselected];

[Light_button setTitleColor:promptLabel.textColor forstate: (UIControlStateNormal)];

Light_button.titleLabel.font = [Uifont systemfontofsize:17];

[Light_button addtarget:self Action: @selector (light_buttonaction:) forcontrolevents:uicontroleventtouchupinside];

[Bottomview Addsubview:light_button];




#pragma mark--click events for Lights

-(void) Light_buttonaction: (UIButton *) button {

if (button.selected = = NO) {//Tap to turn on the light

[Self turnonlight:yes];

button.selected = YES;

_torchimageview.image = [UIImage imagenamed:@ "lit"];

} else {//Click to turn off the lights

[Self turnonlight:no];

button.selected = NO;

_torchimageview.image = [UIImage imagenamed:@ "Torch"];

}

}

-(void) Turnonlight: (BOOL) on {

Self.device = [Avcapturedevice defaultdevicewithmediatype:avmediatypevideo];

if ([_device Hastorch]) {

[_device Lockforconfiguration:nil];

if (ON) {

[_device Settorchmode:avcapturetorchmodeon];

} else {

[_device Settorchmode:avcapturetorchmodeoff];

}

[_device unlockforconfiguration];

}

}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.