SMS Service providers recently asked the company's app in the acquisition of SMS verification code, the current more popular is the use of a similar way to the sliding unlock, our company is taking this way, the design diagram as follows:
Here verify the internal processing logic does not introduce, mainly to share the implementation of the interface effect, the following posted code:
UISlider of the first child class
#import <UIKit/UIKit.h> #define SLIDERWIDTH #define Sliderheight #define SLIDERLABELTEXTCOLOR [Uicolor Color withred:193/255.0 green:193/255.0 blue:193/255.0 alpha:1] #define Sliderlabelbordercolor [UIColor colorWithRed:193/ 255.0 green:193/255.0 blue:193/255.0 alpha:1]. Cgcolor #define Sliderminimumtracktintcolor [uicolor Redcolor] #define Sliderlabelfont #define SLIDERLABELTEXT @ "Sliding unlock /obtain Verification Code "#define THUMBIMAGEWIDTH #define Thumbimageheight @interface checkcodeslider:uislider @end//************** #import "CheckCodeSlider.h" @implementation checkcodeslider// Override the Parent class UISlider method changes the slider frame-(CGRect) Trackrectforbounds: (cgrect) bounds{return cgrectmake (0, 0, Sliderwidth,
Sliderheight); @end instantiate Checkcodeslider, here casually in a viewcontroller written #import "ViewController.h" #import "CheckCodeSlider.h" @interface
Viewcontroller () {Uiimageview *imgview;} @property (Nonatomic, strong) Checkcodeslider *slider; @property (nonatomic, Strong) UILAbel *label; @end @implementation Viewcontroller-(void) viewdidload {[Super viewdidload]; self.view.backgroundColor = [Uicolor White
Color];
[Self createslider]; }-(void) createslider{_slider = [[Checkcodeslider alloc]initwithframe:cgrectmake (0, 0, Sliderwidth, SliderHeight)]; _
Slider.center = Self.view.center;
_slider.minimumtracktintcolor = [Uicolor Clearcolor];
_slider.maximumtracktintcolor = [Uicolor Clearcolor];
_slider.layer.maskstobounds = YES;
_slider.layer.cornerradius = SLIDERHEIGHT/2;
[_slider setthumbimage:[uiimage imagenamed:@ "slider button"] forstate:uicontrolstatenormal];
[_slider addtarget:self Action: @selector (slidervaluechanged:) forcontrolevents:uicontroleventvaluechanged];
[Self.view Addsubview:_slider];
_label = [[Uilabel alloc]initwithframe:cgrectmake (0, 0, Sliderwidth, sliderheight)];
_label.center = Self.view.center;
_label.text = Sliderlabeltext;
_label.font = [Uifont Systemfontofsize:sliderlabelfont];
_label.textalignment = Nstextalignmentcenter; _label.textcolor =Sliderlabeltextcolor;
_label.layer.maskstobounds = YES;
_label.layer.cornerradius = SLIDERHEIGHT/2;
_label.layer.borderwidth = 1;
_label.layer.bordercolor = Sliderlabelbordercolor;
[Self.view Addsubview:_label];
This creates a ImageView overlay on the text that is the same as the slider and lets it slide along the slider in the Slidervaluechanged method. Imgview = [[Uiimageview alloc]initwithframe:cgrectmake (_slider.frame.origin.x-2, _slider.frame.origin.y-2,
Thumbimagewidth+4, thumbimageheight+4)];
Imgview.image = [uiimage imagenamed:@ "slider button"];
[Self.view Addsubview:imgview]; }-(void) slidervaluechanged: (UISlider *) slider{[_slider setValue:slider.value animated:no]; if (Slider.value >0) {_
Slider.minimumtracktintcolor = Sliderminimumtracktintcolor; }else{_slider.minimumtracktintcolor = [Uicolor clearcolor];} imgview.center = Cgpointmake (_slider.frame.origin.x+
slider.value* (sliderwidth-thumbimagewidth) +THUMBIMAGEWIDTH/2, _SLIDER.FRAME.ORIGIN.Y+THUMBIMAGEHEIGHT/2); if (!slider.istracking && slider.value!= 1) {[_slider setvalue:0 animated:yes]; if (sLider.value >0) {_slider.minimumtracktintcolor = Sliderminimumtracktintcolor;} else{_slider.minimumtracktintcolor = [Uicolor clearcolor];} imgview.frame = CGRectMake (_slider.frame.origin.x-2, _
Slider.frame.origin.y-2, Thumbimagewidth+4, thumbimageheight+4); }
}
This can achieve the effect of the above figure, only in slidervaluechanged according to the value of slider to do the appropriate processing.
The above is a small set for you to introduce the iOS sliding unlock, sliding access to the implementation code results of verification code, we hope to help!