swift5:
let alertController = UIAlertController(title: "删除该好友",
message: "确认是否删除该好友", preferredStyle: .alert)
let cancelAction = UIAlertAction(title: "再想想", style: .cancel, handler:{
action in
})
let okAction = UIAlertAction(title: "确认删除", 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