項目開發中,使用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"];
}
}