textField placeholder颜色,位置设置

自定义textField继承自UITextField

重写

- (CGRect)placeholderRectForBounds:(CGRect)bounds

_phoneTF.font = HPFontSemibold(16); // 设置输入文字字号

[_phoneTF setValue:[UIFont systemFontOfSize:14] forKeyPath:@"_placeholderLabel.font"]; // 设置placeholder字号

 

// 设置删除按钮的图片

UIButton *button = [_phoneTF valueForKey:@"_clearButton"];
[button setImage:[UIImage imageNamed:@"icon_login_closed_round"] forState:UIControlStateNormal];
_phoneTF.clearButtonMode = UITextFieldViewModeWhileEditing;

 

- (CGRect)clearButtonRectForBounds:(CGRect)bounds { // 设置删除按钮的位置
    return CGRectMake(bounds.origin.x + bounds.size.width - 20, (bounds.size.height - 20) * 0.5, 20, 20);
}

 

// 设置textField右边的view

_passwordTF.rightView = phoneCodeBtn;
        _passwordTF.rightViewMode = UITextFieldViewModeAlways;
        _passwordTF.rightView.hidden = YES;

posted on 2017-12-19 18:15  土匪7  阅读(215)  评论(0编辑  收藏  举报