昨天由于工作需要赌躺,學(xué)習(xí)了一下富文本逾滥,今天早上先來整理一下烘贴。方便之后的查找禁添。
- 本來以為UIAlertController的message無法進(jìn)行富文本,后來經(jīng)過查找資料桨踪,并且進(jìn)行測試老翘,發(fā)現(xiàn)可以行的通。現(xiàn)將代碼粘貼如下:
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"協(xié)議號" message:@"學(xué)號:123456" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:nil];
NSMutableAttributedString *alertMessageStr = [[NSMutableAttributedString alloc] initWithString:@"學(xué)號:123456"];
[alertMessageStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(0, alertMessageStr.length)];
[alertMessageStr addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(3, 6)];
[alertController setValue:alertMessageStr forKey:@"attributedMessage"];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
1锻离、修改UIAlertController的title的字體顏色铺峭、大小
/*title*/
NSMutableAttributedString *alertTitleStr = [[NSMutableAttributedString alloc] initWithString:@"提示"];
[alertTitleStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0, 2)];
[alertTitleStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 2)];
[alertController setValue:alertTitleStr forKey:@"attributedTitle"];
2、修改UIAlertController的message的字體顏色汽纠、字號大小
/*message*/
NSMutableAttributedString *alertMessageStr = [[NSMutableAttributedString alloc] initWithString:@"請修改輸入內(nèi)容"];
[alertMessageStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18] range:NSMakeRange(0, 7)];
[alertMessageStr addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(0, 3)];
[alertMessageStr addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(3, 2)];
[alertMessageStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(5, 2)];
[alertController setValue:alertMessageStr forKey:@"attributedMessage"];
好了卫键、今天就整理到這里。