您可以使用 NSAttributedString 来设置 UITextField 的 placeholder 颜色。以下是用于设置 placeholder 颜色的 Objective-C 代码示例:

NSString *placeholderText = 'Enter text';
UIColor *placeholderColor = [UIColor redColor];

NSAttributedString *attributedPlaceholder = [[NSAttributedString alloc] initWithString:placeholderText attributes:@{NSForegroundColorAttributeName: placeholderColor}];
textField.attributedPlaceholder = attributedPlaceholder;

在上面的示例中,我们首先创建了一个 NSString 对象 'placeholderText',它包含了要显示的 placeholder 文本。然后,我们创建了一个 UIColor 对象 'placeholderColor',它表示了 placeholder 的颜色。接下来,我们使用 NSAttributedString 的 initWithString:attributes: 方法创建了一个带有指定文本和颜色的 NSAttributedString 对象 'attributedPlaceholder'。最后,我们将 'attributedPlaceholder' 赋值给 UITextField 的 attributedPlaceholder 属性,以设置 placeholder 的颜色。

请注意,以上代码示例中的 'textField' 是指您的 UITextField 对象。确保将其替换为您的实际 UITextField 对象的引用。


原文地址: https://www.cveoy.top/t/topic/cvRe 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录