UITextField
有一个重要的属性placeholder
,一般情况下能满足我们的需求。但是有时候我也也许会想要修改placeholder
的文本颜色,此时就需要通过修改它的attributedPlaceholder
来实现。
废话不多说,直接上代码:
UITextField *heightTF = [[UITextField alloc] init];
heightTF.placeholder = @"请输入内容";
heightTF.attributedPlaceholder = [[NSAttributedString alloc] initWithString:heightTF.placeholder attributes:@{NSForegroundColorAttributeName:[UIColor lightGrayColor]}];