親測: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,250評論 4 61
  • 黃發初覆額,兩小無猜嫌;郎自阡陌至,繞床弄青梅。竹馬尚年少,難解情何起;垅上相逐嬉,為君不展眉。我憐君孤憫,君嘆我...
    個人日常腦洞堆積地閱讀 314評論 0 0
  • /* Optional 我們使用類型后面加上?的語法只不過是Optional類型的語法糖,而實際這個類型是一個en...
    fordring2008閱讀 593評論 0 0
  • 臨近下班,我的作業還沒著落! 天氣太熱,像我這等肉厚的女生,走在柏油馬路上,直感覺那強烈的熱浪,炙烤著我...
    北墨貓小漁閱讀 369評論 0 2
  • 什么是網貸_華融道理財 什么是網貸_華融道理財 什么是網貸_華融道理財
    伊輪閃22718閱讀 221評論 0 0