iOS 分割輸入驗證碼的視覺效果

2021-08-15 02:05:09 字數 2502 閱讀 9748

通常情況下,在使用者註冊或者登入的時候我們會用到手機驗證碼,而有時就會需要,分割輸入驗證碼的視覺效果。

那這種情況,我們怎麼實現呢?

在網上查了很多,好多都只是給了實現**,給的東西都不是很詳細,貼上過來,有好多值不知道是從**來的,還有的就是需要第三方,但是第三方**量就太多了,會使程式變大,雖然影響不大,但是完全沒有必要

先看實現**:

我們要建立兩個類:vertificationcodeinputview 繼承 uiview, vertificationcodeinputlabel 繼承uilabel

先看vertificationcodeinputview.h檔案

@protocol gettextfieldcontentdelegate //返回搜尋內容

-(void)returntextfieldcontent:(nsstring*)content;

@end

@inte***ce vertificationcodeinputview : uiview

@property (assign,nonatomic,readwrite)id delegate;

/**背景*/

@property (nonatomic,copy)nsstring *backgroudimagename;

/**驗證碼/密碼的位數*/

@property (nonatomic,assign)nsinteger numberofvertificationcode;

/**控制驗證碼/密碼是否密文顯示*/

@property (nonatomic,assign)bool securetextentry;

/**驗證碼/密碼內容,可以通過該屬性拿到驗證碼/密碼輸入框中驗證碼/密碼的內容*/

@property (nonatomic,copy)nsstring *vertificationcode;

-(void)becomefirstresponder;

接下來看vertificationcodeinputview.m檔案

#import "vertificationcodeinputview.h"

#import "vertificationcodeinputlabel.h"

@inte***ce vertificationcodeinputview () /**用於獲取鍵盤輸入的內容,實際不顯示*/

@property (nonatomic,strong)uitextfield *textfield;

/**驗證碼/密碼輸入框的背景*/

@property (nonatomic,strong)uiimageview *backgroundimageview;

/**實際用於顯示驗證碼/密碼的label*/

@property (nonatomic,strong)vertificationcodeinputlabel *label;

@end

@implementation vertificationcodeinputview

- (instancetype)initwithframe:(cgrect)frame

return self;

}#pragma mark --------- 設定背景

- (void)setbackgroudimagename:(nsstring *)backgroudimagename

- (void)setnumberofvertificationcode:(nsinteger)numberofvertificationcode

- (void)setsecuretextentry:(bool)securetextentry

-(void)becomefirstresponder

- (void)touchesbegan:(nsset*)touches withevent:(uievent *)event

#pragma mark ------ 時時監測輸入框的內容

- (bool)textfield:(uitextfield *)textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring *)string

// 按照指定的格式繪製驗證碼/密碼

- (void)drawrect:(cgrect)rect1

@end

@implementation viewcontroller

- (void)viewdidload

#pragma mark --------- 獲取驗證碼

-(void)returntextfieldcontent:(nsstring *)content

- (void)didreceivememorywarning

@end

iOS 分割輸入驗證碼的視覺效果

自定義 view inte ce idvertificationcodeinputview uiview 背景 property nonatomic,copy nsstring backgroudimagename 驗證碼 密碼的位數 property nonatomic,assign nsinte...

iOS驗證碼及密碼輸入框的實現

1.輸入框的實現分析 主要由可見的6個方格仔組成,這裡可以看成6個輸入框或者顯示標籤。輸入6個數字,組成密碼或者驗證碼,可以建立6個textfield拼接,也可以用6個label去顯示,具體做法都可以,主要是實現的邏輯。首先使用者在來到輸入頁面的時候,鍵盤一般是彈起的,所以得有個textfiled作...

js vue實現6位驗證碼輸入框效果

說明因業務需求需要有個6框連續輸入的元件,這邊是直接畫了6個輸入框,然後通過一些事件控制輸入框的輸入順序,以及一些特殊處理。效果 元件原始碼 v for item,index in captchas key index v model item.num id captcha index input ...