swift5:
let alertController = UIAlertController(title: "刪除該好友",
message: "確認(rèn)是否刪除該好友", preferredStyle: .alert)
let cancelAction = UIAlertAction(title: "再想想", style: .cancel, handler:{
action in
})
let okAction = UIAlertAction(title: "確認(rèn)刪除", style: .default, handler: {
action in
self.deleteFriend()
})
okAction.setValue(UIColor.red, forKey:"titleTextColor")//alertController按鈕顏色
alertController.addAction(cancelAction)
alertController.addAction(okAction)
self.present(alertController, animated: true, completion: nil)
UIAlertController *alertController = [[UIAlertController alloc] init];
NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:@"抵用券選擇"];
[title addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:NSMakeRange(0,5)];
[title addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0,5)];
[alertController setValue:title forKey:@"attributedTitle"];
if ([[[UIDevice currentDevice]systemVersion]floatValue]>8.3) {
UIAlertAction*cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
//修改取消按鈕顏色
[cancelAction setValue:[UIColor redColor] forKey:@"_titleTextColor"];
[alertController addAction:cancelAction];
for (L_yh *yh in _model.l_yh) {
UIAlertAction *action = [UIAlertAction actionWithTitle:yh.name style:UIAlertActionStyleDefault handler:nil];
//修改按鈕顏色驾凶、這里如果加了判斷
[action setValue:_kMainColor forKey:@"_titleTextColor"];
[alertController addAction:action];
}
}else {
UIAlertAction*cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
[alertController addAction:cancelAction];
//修改取消按鈕顏色
for (L_yh *yh in _model.l_yh) {
UIAlertAction *action = [UIAlertAction actionWithTitle:yh.name style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:action];
}
alertController.view.tintColor = _kMainColor;
}
[_controll presentViewController:alertController animated:YES completion:nil];
自定義action對的顏色和大小
https://github.com/Friend-LGA/LGAlertView