法一:
self.nameTextField.placeholder = @"Username (NOT Email Address)";
[self.nameTextField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
法二:
NSAttributedString * placeholder= [[NSAttributedString alloc] initWithString:@" Username(NOT Email Address)" attributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
self.nameTextField.attributedPlaceholder = placeholder;
本文介绍了两种在iOS应用中使用Swift为UITextField设置占位符文本及其颜色的方法。第一种方法通过直接设置颜色属性实现,第二种则利用NSAttributedString来定义文本样式。
373

被折叠的 条评论
为什么被折叠?



