1. 程式人生 > >iOS 動態生成驗證模組

iOS 動態生成驗證模組

typedef NS_ENUM(NSUInteger,WSQIdentifyingCodeType){

    DefaultType  = 0,     // 預設數字、字母、中文混合

    CountType = 1        // 加法

    

};



/* 返回結果*/

typedef void(^resultBackBlock)(NSString * backString);


@interface

WSQIdentifyingView :UIView


/**

 *  初始化大小與型別

 *

 *  param frame 大小

 *  param type  型別

 */

- (instancetype)initWithFrame:(CGRect)frame WithType:(WSQIdentifyingCodeType)type;


/**

 *  獲取當前頁面上顯示的字母或計算的值

 *

 *  param block

傳值

 */

- (void)getResultString:(resultBackBlock)result;






-(void)getResultString:(resultBackBlock)result{

    resultBlock = result;

}




- (instancetype)initWithFrame:(CGRect)frame WithType:(WSQIdentifyingCodeType)type

{

   

if (self = [superinitWithFrame:frame]) {

        

        self.layer.cornerRadius =5.0; //設定layer圓角半徑

        self.layer.masksToBounds =YES;

        self.backgroundColor =kRandomColor;

        

        if (type ==DefaultType) {

            

            [selfchangeCaptcha];

            

        }elseif (type == CountType){

            

            [selfchangeCount];

        }

        

        _CodeType = type;

    }

    

    returnself;

}





更多完整詳細dome:http://download.csdn.net/download/qq_33646395/9987338