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}];

你可能感兴趣的:(KVC 修改textFiled 属性)