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];
}
}