系統(tǒng)的 UIAlertController 封裝的很漂亮,用block代替之前 UIAlertView 的代理屋讶,用起來更方便的,但是其曝露出來的接口也不多如果要個性化一些東西,比如字體大小祭芦、顏色就不是很方便了移层,下面總結(jié)一下 UIAlertController 更改字體的方法仍翰,以作備忘:
1、UIAlertController 的標(biāo)題(Title)观话、和描述(Message) 可以更改字體的大小和顏色
NSAttributedString *attTitle = [[NSAttributedString alloc] initWithString:title attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:16], NSForegroundColorAttributeName : [UIColor colorWithHexstring:@"333333"]}];
[alert setValue:attTitle forKey:@"attributedTitle"];
NSAttributedString *attMessage = [[NSAttributedString alloc] initWithString:message attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:16], NSForegroundColorAttributeName : [UIColor colorWithHexstring:@"333333"]}];
[alert setValue:attMessage forKey:@"attributedMessage"];
這樣可以設(shè)置 alert 的title予借,和 message 。注意會覆蓋 alert 初始化時填寫的值频蛔。
2灵迫、UIAlertController 的按鈕(action) 可以更改字體顏色,字體大小沒找到怎么改
UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
[sureAction setValue:[UIColor colorWithHexstring:@"18a74f"] forKey:@"titleTextColor"];