亲测:UITextView 设置系统私有属性_placeholderLabel 兼容版本

项目开发中,使用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"];
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,223评论 4 61
  • 黄发初覆额,两小无猜嫌;郎自阡陌至,绕床弄青梅。竹马尚年少,难解情何起;垅上相逐嬉,为君不展眉。我怜君孤悯,君叹我...
    个人日常脑洞堆积地阅读 312评论 0 0
  • /* Optional 我们使用类型后面加上?的语法只不过是Optional类型的语法糖,而实际这个类型是一个en...
    fordring2008阅读 593评论 0 0
  • 临近下班,我的作业还没着落! 天气太热,像我这等肉厚的女生,走在柏油马路上,直感觉那强烈的热浪,炙烤着我...
    北墨猫小渔阅读 369评论 0 2
  • 什么是网贷_华融道理财 什么是网贷_华融道理财 什么是网贷_华融道理财
    伊轮闪22718阅读 221评论 0 0