美文网首页iOS个人修养IOSiOS备忘录
酷炫的文本输入框FGGTextField

酷炫的文本输入框FGGTextField

作者: CGPointZero | 来源:发表于2016-09-19 12:10 被阅读205次

    FGGTextField


    Introduction

    一个超级酷炫的文本输入框,继承自UITextField,依赖于AJWValidator.用于实现文本输入的实时监测。


    Installtion

    Manual:

    Download This Project and drag the FGGTextField folder into your peroject, do not forget to ensure "copy item if need" being selected.

    Cocoapods:

    pod 'FGGTextField', '~> 1.0.0'
    

    Usage

    Just import the header file:import "FGGTextField.h"

    FGGTextField *tf=[[FGGTextField alloc]initWithFrame:CGRectMake(10, 100, kWidth-20, 40)];
    tf.placeholder=@"请输入邮箱";
    tf.errorText=@"邮箱格式不对";
    tf.validatorText=@"邮箱";
    [self.view addSubview:tf];
    tf.borderStyle=UITextBorderStyleRoundedRect;
    tf.keyboardType=UIKeyboardTypeEmailAddress;
    
     AJWValidator *validator=[AJWValidator validatorWithType:AJWValidatorTypeString];
     [validator addValidationToEnsureValidEmailWithInvalidMessage:tf.errorText];
     [tf  ajw_attachValidator:validator];
     __weak typeof(validator) weak_validator=validator;
     validator.validatorStateChangedHandler=^(AJWValidatorState state){
                
            switch (state) {
                case AJWValidatorValidationStateValid:
                    tf.highlightState=FGGTextFieldHighlightStateValidator;
                    leftView.text=@"😁";
                    break;
                 case AJWValidatorValidationStateInvalid:
                     tf.highlightState=FGGTextFieldHighlightStateWrong;
                     leftView.text=@"😟";
                     break;
                 default:
                     break;
             }
             if(weak_validator.isValid){
                    
                 NSLog(@"格式正确✅");
             }
         };
    

    Example

    1.在项目中导入:FGGTextField.h

    2.创建FGGTextField的对象

    FGGTextField *tf=[[FGGTextField alloc]initWithFrame:CGRectMake(50, 100, 200, 40)];

    3.设置属性

    tf.placeholder=@"请输入邮箱";

    tf.errorText=@"邮箱格式不正确";

    tf.validatorText=@"邮箱";



    tf.borderStyle=UITextBorderStyleRoundedRect;

    tf.keyboardType=UIKeyboardTypeEmailAddress;

    4.添加到父视图
    如果有问题,可以给我发邮件:newbox0512@yahoo.com

    About Me

    I attached my code on github,touch to download:->FGGTextField


    @CGPoitZero

    相关文章

      网友评论

      本文标题:酷炫的文本输入框FGGTextField

      本文链接:https://www.haomeiwen.com/subject/cmxnettx.html