贴上代码
UITextField *textField = [UITextField new];
NSString *placeHolderStr = @"我是placeholder";
textField.placeholder = placeHolderStr;
NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:placeHolderStr];
[placeholder addAttribute:NSForegroundColorAttributeName
value:[UIColor whiteColor]
range:NSMakeRange(0, placeHolderStr.length)];
[placeholder addAttribute:NSFontAttributeName
value:[UIFont boldSystemFontOfSize:16]
range:NSMakeRange(0, placeHolderStr.length)];
textField.attributedPlaceholder = placeholder;

本文介绍如何使用Swift为UITextField设置带有颜色和字体加粗效果的自定义占位符文本。通过NSAttributedString对占位符进行样式调整,实现更加美观的界面显示。

468

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



