国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

改變UIAlertController的標題、內容的字體和顏色

2019-11-09 17:05:11
字體:
來源:轉載
供稿:網友

在開發中,彈出框是必不可少的,通常情況下,我們只要彈出系統自帶的彈出框就可以。but,在某些情況下,萬惡的UI會要求你修改顯示文字的大小、顏色,雖然系統自帶有一種紅色字體的UIAlertAction,但是這種Action并不能放在Cancel位置,所以,更多時候,需要我們自己修改文字字體和顏色。我采用的方法是KVC:正常情況下,我們配置出來的UIAlertController是這樣的:

123.png

或者是這樣:

345.png

代碼如下:

   UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"提示內容" PReferredStyle:UIAlertControllerStyleAlert];//    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"提示內容" preferredStyle:UIAlertControllerStyleActionSheet];    UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"Default" style:UIAlertActionStyleDefault handler:nil];    UIAlertAction *destructiveAction = [UIAlertAction actionWithTitle:@"Destructive" style:UIAlertActionStyleDestructive handler:nil];    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];    [alertController addAction:defaultAction];    [alertController addAction:destructiveAction];    [alertController addAction:cancelAction];    [self presentViewController:alertController animated:YES completion:nil];

代碼里展示了系統提供的三種UIAlertAction,現在我們要對文字的字體和顏色進行設置:

1.標題和提示內容的文字設置代碼如下://修改title  NSMutableAttributedString *alertControllerStr = [[NSMutableAttributedString alloc] initWithString:@"提示"];  [alertControllerStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 2)];  [alertControllerStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:NSMakeRange(0, 2)];  if (alertController valueForKey:@"attributedTitle") {      [alertController setValue:alertControllerStr forKey:@"attributedTitle"];  }  //修改message  NSMutableAttributedString *alertControllerMessageStr = [[NSMutableAttributedString alloc] initWithString:@"提示內容"];  [alertControllerMessageStr addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(0, 4)];  [alertControllerMessageStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0, 4)];  if (alertController valueForKey:@"attributedMessage") {      [alertController setValue:alertControllerMessageStr forKey:@"attributedMessage"];  }效果如下:123.png2.設置按鈕文字,就拿取消按鈕距離:代碼如下:  //修改按鈕  if (cancelAction valueForKey:@"titleTextColor") {      [cancelAction setValue:[UIColor redColor] forKey:@"titleTextColor"];  }效果如下:
上一篇:Glide加載圖片

下一篇:ffmpeg學習

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 仪陇县| 江口县| 徐州市| 安新县| 汝城县| 平原县| 阿鲁科尔沁旗| 嘉义市| 福安市| 防城港市| 宣武区| 庄河市| 晋城| 景洪市| 青岛市| 湖南省| 辽阳县| 富裕县| 囊谦县| 周宁县| 南城县| 马关县| 东丽区| 全椒县| 师宗县| 福海县| 和顺县| 普定县| 芦溪县| 南召县| 鱼台县| 肇州县| 香港 | 英德市| 临安市| 鄂伦春自治旗| 长阳| 马公市| 长阳| 连平县| 漳浦县|