在iOS开发中,你可以通过以下代码来设置UITextField的placeholder颜色:

Objective-C代码:

UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 200, 30)];
textField.placeholder = @"请输入";
textField.textColor = [UIColor blackColor]; // 设置文本颜色
textField.font = [UIFont systemFontOfSize:14]; // 设置字体大小
[textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"]; // 设置placeholder颜色
[textField setValue:[UIFont boldSystemFontOfSize:14] forKeyPath:@"_placeholderLabel.font"]; // 设置placeholder字体大小

通过上述代码,你可以设置UITextField的文本颜色、字体大小以及placeholder的颜色和字体大小。其中,通过setValue:forKeyPath:方法设置placeholder的颜色和字体大小。

注意:使用setValue:forKeyPath:方法设置placeholder的颜色和字体大小可能会违反苹果的规则。在实际开发中,建议使用自定义的UITextField子类来实现该功能,以免被苹果拒绝上架

iOS开发 uitextfield placeholder 颜色设置oc代码

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

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