親測(cè):UITextView 設(shè)置系統(tǒng)私有屬性_placeholderLabel 兼容版本

項(xiàng)目開發(fā)中,使用UITextView 設(shè)置系統(tǒng)私有屬性_placeholderLabel,8.1.3版本出現(xiàn)崩潰,特別為此進(jìn)行版本支持測(cè)試,最后結(jié)果_placeholderLabel,支持版本為8.3

UIAlertController 中的 UIAlertAction 設(shè)置按鈕的文字顏色"TitleTextColor" 支持版本為8.3

@interface UITextView (TXPlaceholder)

/**
 設(shè)置textView placeholder

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

@end
@implementation UITextView (TXPlaceholder)

/**
 設(shè)置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
/**
 設(shè)置alert按鈕顏色
 
 @param color
 @param action
 */
+ (void)setActionTitleTextColor:(UIColor *)color action:(UIAlertAction *)action {
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.3) {
        [action setValue:color forKey:@"titleTextColor"];
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫(kù)、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,256評(píng)論 4 61
  • 黃發(fā)初覆額,兩小無(wú)猜嫌;郎自阡陌至,繞床弄青梅。竹馬尚年少,難解情何起;垅上相逐嬉,為君不展眉。我憐君孤憫,君嘆我...
    個(gè)人日常腦洞堆積地閱讀 332評(píng)論 0 0
  • /* Optional 我們使用類型后面加上?的語(yǔ)法只不過是Optional類型的語(yǔ)法糖,而實(shí)際這個(gè)類型是一個(gè)en...
    fordring2008閱讀 615評(píng)論 0 0
  • 臨近下班,我的作業(yè)還沒著落! 天氣太熱,像我這等肉厚的女生,走在柏油馬路上,直感覺那強(qiáng)烈的熱浪,炙烤著我...
    北墨貓小漁閱讀 391評(píng)論 0 2
  • 什么是網(wǎng)貸_華融道理財(cái) 什么是網(wǎng)貸_華融道理財(cái) 什么是網(wǎng)貸_華融道理財(cái)
    伊輪閃22718閱讀 243評(píng)論 0 0

友情鏈接更多精彩內(nèi)容