代碼:
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Title" message:@"message" preferredStyle:UIAlertControllerStyleAlert];
// 修改title鳖粟、message的內(nèi)容拙绊、字號泳秀、顏色榄攀,使用的key值是 "attributedTitle" 和 "attributedMessage"
NSMutableAttributedString *message = [[NSMutableAttributedString alloc] initWithString:alertController.message];
// 修改對齊方式
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setAlignment:NSTextAlignmentLeft];
[message addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [[message string] length])];
[message addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(0, [[message string] length])];
[message addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, [[message string] length])];
[alertController setValue:message forKey:@"attributedMessage"];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"點擊了Cancel");
}];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"點擊了OK");
}];
// 修改按鈕的顏色
[cancelAction setValue:[UIColor blueColor] forKey:@"_titleTextColor"];
[okAction setValue:[UIColor greenColor] forKey:@"_titleTextColor"];
[alertController addAction:okAction];
[alertController addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者