- 最近項(xiàng)目時(shí)發(fā)現(xiàn)當(dāng)在10以上設(shè)備上設(shè)置 describeField.borderStyle = UITextBorderStyleNone;
輸入結(jié)束時(shí)候文字下移;在10以下設(shè)備卻沒(méi)有這種情況出現(xiàn).
當(dāng)出現(xiàn)該情況時(shí),可設(shè)置textField的leftView
UITextField *field = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 320, 30)];
field.leftView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 1, 21)];
field.leftViewMode = UITextFieldViewModeAlways;
2.1 方法一:通過(guò)attributedPlaceholder屬性修改Placeholder顏色
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"請(qǐng)輸入占位文字" attributes:
@{NSForegroundColorAttributeName:[UIColor redColor], NSFontAttributeName:textField.font }];
textField.attributedPlaceholder = attrString;
2.2 方法二:通過(guò)KVC修改Placeholder顏色
[textField1 setValue:[UIColor greenColor]forKeyPath:@"_placeholderLabel.textColor"];
2.3方法三:通過(guò)重寫(xiě)UITextField的drawPlaceholderInRect:方法修改Placeholder顏色
/ 重寫(xiě)此方法
-(void)drawPlaceholderInRect:(CGRect)rect {
// 計(jì)算占位文字的 Size
CGSize placeholderSize = [self.placeholder sizeWithAttributes: @{NSFontAttributeName : self.font}];
[self.placeholder drawInRect:CGRectMake(0, (rect.size.height - placeholderSize.height)/2, rect.size.width, rect.size.height) withAttributes:
@{NSForegroundColorAttributeName : [UIColor blueColor],
NSFontAttributeName : self.font}];
}