iOS swipe to unlock/swipe to get Verification code effect implementation

Source: Internet
Author: User
Tags uikit

Recently, SMS service providers require the company's app in the acquisition of SMS verification code, plus check code, the current is more popular is the use of similar sliding to unlock the way, our company took this way, the design diagram is as follows:

Here check the internal processing logic is not introduced, the main share of the interface effect of implementation, the following paste code:

First sub-class UISlider

#import <UIKit/UIKit.h>#define sliderwidth#define sliderheight#define sliderlabeltextcolor [Uicolor colorwithred: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 @ "swipe to unlock/Get verification Code"#define thumbimagewidth#define thumbimageheight@InterfaceCheckcodeslider:uislider@end//*******************************************************#import "CheckCodeSlider.h"@implementation Checkcodeslider//Overwrite parent class UISlider method change Slider frame-(CGRect) Trackrectforbounds: (CGRect) bounds{returnCGRectMake (0,0, Sliderwidth, sliderheight);} @end

Then instantiate Checkcodeslider, which is written in a viewcontroller.

#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 Whitecolor];[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. ViewAddsubview:_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. ViewAddsubview:_label];This creates a imageview that is the same as the slider to cover the text and slide it 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. ViewAddsubview:imgview];}-(void) slidervaluechanged: (UISlider *) slider{[_slider Setvalue:slider. ValueAnimated: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:0Animated: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 be achieved in the effect, only need to slidervaluechanged according to the value of the slider to do the corresponding processing on the line.

iOS swipe to unlock/swipe to get Verification code effect implementation

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.