屏幕快照 2016-12-13 下午5.35.35.png有时候,UI妹子的设计稿并不按常规来,比如以下设计,让
placeHolder
居中显示,好在苹果API中提供了TextField
的attributedPlaceholder
属性来解决问题
对于以上的UI效果其实用UITextField
的属性attributedPlaceholder
,并结合NSMutableParagraphStyle
使用就可以是占位符居中显示.
具体代码如下
- (QDDLTextField *)phoneTextField
{
if (_phoneTextField == nil) {
_phoneTextField = [[QDDLTextField alloc] initWithFrame:CGRectZero leftView:nil inset:KWFloat(30)];
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
style.alignment = NSTextAlignmentCenter;
NSAttributedString *attri = [[NSAttributedString alloc] initWithString:@"请填写手机号" attributes:@{NSForegroundColorAttributeName:QDDCOLOR(163, 163, 163, 1),NSFontAttributeName:[UIFont qdd_fontOfSize:34], NSParagraphStyleAttributeName:style}];
_phoneTextField.attributedPlaceholder = attri;
_phoneTextField.layer.borderColor = QDDCOLOR(221, 221, 221, 1).CGColor;
_phoneTextField.layer.borderWidth = 1;
_phoneTextField.layer.cornerRadius = 2;
_phoneTextField.keyboardType = UIKeyboardTypePhonePad;
}
return _phoneTextField;
}```
网友评论