iOS開發 UIAlertController的 title、message、button的屬性更改
// ------------title ---------
NSMutableAttributedString *attTitleString = [[NSMutableAttributedString alloc] initWithString:titleString];
[_alertController setValue:attTitleString forKey:@"attributedTitle"];
// -----------message --------
NSMutableAttributedString *attMsgString = [[NSMutableAttributedString alloc] initWithString:messageString];
// 設定字型
[attMsgString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(0, attMsgString.length)];
// 設定顏色
[attMsgString addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0, 10)];
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
// 設定行間距
[paragraph setLineSpacing:3];
// 設定段間距
[paragraph setParagraphSpacingBefore:5];
// 設定對齊方式
[paragraph setAlignment:NSTextAlignmentLeft];
// 設定書寫方向
[paragraph setBaseWritingDirection:NSWritingDirectionLeftToRight];
[attMsgString addAttribute:NSParagraphStyleAttributeName value:paragraph range:NSMakeRange(0, attMsgString.length)];
[_alertController setValue:attMsgString forKey:@"attributedMessage"];
// ----按鈕顏色------
NSArray *actionArr = [_alertController actions];
[actionArr.firstObject setTitle:alertTitle];
[actionArr.firstObject setValue:[UIColor orangeColor] forKey:@"titleTextColor"];