KVC 修改textFiled 属性

[self.purchaseTextFiled setValue:kColor_PlaceHolderColor_888888 forKeyPath:@"_placeholderLabel.textColor"];

[self.purchaseTextFiled setValue:[UIFont boldSystemFontOfSize:15] forKeyPath:@"_placeholderLabel.font"];

一种方法重写 - (void)drawPlaceholderInRect:(CGRect)rect 方法

参考 UITextField and attributedPlaceholder

You should subclass of UITextField, and override the method of:(重写方法) 


另外一种写法 :根据 textFiled 的attributedPlaceholder 属性

// 购买金额

self.tfAmount.font = kFont_18;

NSMutableParagraphStyle *style = [self.tfAmount.defaultTextAttributes[NSParagraphStyleAttributeName] mutableCopy];

style.minimumLineHeight = self.tfAmount.font.lineHeight - (self.tfAmount.font.lineHeight - kFont_14.lineHeight) / 2.0;

self.tfAmount.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"100元起投资,单笔最多可购买5万" attributes:@{NSForegroundColorAttributeName: kColor_PlaceHolderColor,NSFontAttributeName : kFont_14,NSParagraphStyleAttributeName : style}];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容