UITextfield常用屬性

@property(nonatomic,strong) UIImageView*bgImageView;//登錄背景
@property(nonatomic,strong) UITextField*phoneNumField;//手機號輸入框
@property(nonatomic,strong) UITextField*passwordField;//密碼輸入框


    //背景圖
    _bgImageView = [[UIImageView alloc]initWithFrame:self.view.frame];
    _bgImageView.userInteractionEnabled = YES;
    _bgImageView.backgroundColor = [UIColor grayColor];
    _bgImageView.image = [UIImage imageNamed:@""];
    [self.view addSubview:_bgImageView];

    //手機號輸入框
    _phoneNumField = [[UITextField alloc] initWithFrame:CGRectMake(0.0f, 80.0f, ScreenWidth, 50.0f)];
    [_phoneNumField setBorderStyle:UITextBorderStyleNone]; //外框類型

    _phoneNumField.placeholder = @"請輸入賬號"; //默認顯示的字
    _phoneNumField.backgroundColor = [UIColor whiteColor];
    _phoneNumField.secureTextEntry = NO; //密碼

    _phoneNumField.autocorrectionType = UITextAutocorrectionTypeNo;
    _phoneNumField.autocapitalizationType = UITextAutocapitalizationTypeNone;
    _phoneNumField.returnKeyType = UIReturnKeyDone;
    _phoneNumField.clearButtonMode = UITextFieldViewModeWhileEditing; //編輯時會出現個修改X

    _phoneNumField.delegate = self;



    [_bgImageView addSubview:_phoneNumField];

    //手機號label
    UILabel*phoneLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 80, 50)];
    phoneLabel.text = @"賬號";
    phoneLabel.textAlignment = NSTextAlignmentLeft;
    phoneLabel.textColor = [UIColor blackColor];
    phoneLabel.font = [UIFont systemFontOfSize:13];


    UIView*phoneLeftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 80, 50)];
    phoneLeftView.backgroundColor = [UIColor redColor];
    [phoneLeftView addSubview:phoneLabel];

    _phoneNumField.leftViewMode=UITextFieldViewModeAlways;
    _phoneNumField.leftView=phoneLeftView;

    //發送驗證碼
    UIButton*button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 80, 50);
    NSMutableAttributedString *content = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"發送驗證碼"]];
    NSRange contentRange = {0,[content length]};
    [content addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:contentRange];
    [button setAttributedTitle:content  forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:13];
    UIView*phoneRightView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 80, 50)];
    phoneRightView.backgroundColor = [UIColor yellowColor];
    [phoneRightView addSubview:button];

    _phoneNumField.rightViewMode=UITextFieldViewModeAlways;
    _phoneNumField.rightView=phoneRightView;

    //密碼輸入框
    _passwordField = [[UITextField alloc] initWithFrame:CGRectMake(0.0f, 130.5f, ScreenWidth, 50.0f)];
    [_passwordField setBorderStyle:UITextBorderStyleNone]; //外框類型

    _passwordField.placeholder = @"6-12位數字或字母"; //默認顯示的字
    _passwordField.backgroundColor = [UIColor whiteColor];
    _passwordField.secureTextEntry = YES; //密碼

    _passwordField.autocorrectionType = UITextAutocorrectionTypeNo;
    _passwordField.autocapitalizationType = UITextAutocapitalizationTypeNone;
    _passwordField.returnKeyType = UIReturnKeyDone;
    _passwordField.clearButtonMode = UITextFieldViewModeWhileEditing; //編輯時會出現個修改X

    _passwordField.delegate = self;



    [_bgImageView addSubview:_passwordField];
    //登錄密碼label
    UILabel*passwordLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 80, 50)];
    passwordLabel.text = @"密碼";
    passwordLabel.textAlignment = NSTextAlignmentLeft;
    passwordLabel.textColor = [UIColor blackColor];
    passwordLabel.font = [UIFont systemFontOfSize:13];

    UIView*passwordLeftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 80, 50)];
    passwordLeftView.backgroundColor = [UIColor redColor];
    [passwordLeftView addSubview:passwordLabel];

    _passwordField.leftViewMode=UITextFieldViewModeAlways;
    _passwordField.leftView=passwordLeftView;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章