美文网首页
亲测:UITextView 设置系统私有属性_placehold

亲测:UITextView 设置系统私有属性_placehold

作者: Roger_max | 来源:发表于2017-07-28 11:19 被阅读656次

项目开发中,使用UITextView 设置系统私有属性_placeholderLabel,8.1.3版本出现崩溃,特别为此进行版本支持测试,最后结果_placeholderLabel,支持版本为8.3

UIAlertController 中的 UIAlertAction 设置按钮的文字颜色"TitleTextColor" 支持版本为8.3

@interface UITextView (TXPlaceholder)

/**
 设置textView placeholder

 @param text 文字
 @param textColor 颜色
 @param font 字体
 */
- (void)addPlaceholderWithText:(NSString *)text
                     textColor:(UIColor *)textColor
                          font:(UIFont *)font;

@end
@implementation UITextView (TXPlaceholder)

/**
 设置textView placeholder
 
 @param text 文字
 @param textColor 颜色
 @param font 字体
 */
- (void)addPlaceholderWithText:(NSString *)text
                     textColor:(UIColor *)textColor
                          font:(UIFont *)font {
    UILabel *placeHolderLabel = [[UILabel alloc] init];
    placeHolderLabel.text = text;
    placeHolderLabel.numberOfLines = 0;
    placeHolderLabel.textColor = textColor;
    [placeHolderLabel sizeToFit];
    [self addSubview:placeHolderLabel];
    // same font
    placeHolderLabel.font = font;

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.3) {
        [self setValue:placeHolderLabel forKey:@"_placeholderLabel"];
    }
}

@end
/**
 设置alert按钮颜色
 
 @param color
 @param action
 */
+ (void)setActionTitleTextColor:(UIColor *)color action:(UIAlertAction *)action {
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.3) {
        [action setValue:color forKey:@"titleTextColor"];
    }
}

相关文章

网友评论

      本文标题:亲测:UITextView 设置系统私有属性_placehold

      本文链接:https://www.haomeiwen.com/subject/lrsxlxtx.html