您的位置:首页 > 其它

如何更改textField的placeholder的左边距以及颜色字号等

2016-05-12 15:33 363 查看
UITextField *tfPhone = [[UITextField
alloc] init];
tfPhone.leftView = [[UIView
alloc] initWithFrame:CGRectMake(0,
0, 15,
40)];
tfPhone.leftViewMode =
UITextFieldViewModeAlways;
self.tfPhone = tfPhone;
tfPhone.delegate =
self;
tfPhone.backgroundColor =
UIColorFromRGBWithAlpha(0xd5d5d5,
1.0);

NSMutableParagraphStyle *style = [tfPhone.defaultTextAttributes[NSParagraphStyleAttributeName]
mutableCopy];

style.minimumLineHeight = tfPhone.font.lineHeight - (tfPhone.font.lineHeight
- [UIFont systemFontOfSize:14].lineHeight) /
2.0;

tfPhone.attributedPlaceholder = [[NSAttributedString
alloc]
initWithString:@"请输入您的手机号"
attributes:@{NSParagraphStyleAttributeName : style,
NSFontAttributeName : [UIFont
systemFontOfSize:14],
NSForegroundColorAttributeName: UIColorFromRGBWithAlpha(0x878787,
1.0)}];

tfPhone.textColor =
UIColorFromRGBWithAlpha(0x878787,
1.0);
[self
addSubview:tfPhone];
tfPhone.layer.cornerRadius =
5;
tfPhone.layer.masksToBounds =
YES;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: