iOS开发笔记-30: oc - swift5 UIAlertController (ActionSheet类型)

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

https://github.com/szk-atmosphere/MSAlertController

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,569评论 2 45
  • 人与人之间的沟通很重要,我本身性格教内向,能不说话就不说话,在和领导的沟通中,语言简洁明了,直奔主题,多一个字都尽...
    或许我该换一种活法了阅读 207评论 0 0
  • 头痛,耳朵抽筋,有生以来最痛苦的一次,除了药物,其他任何辅助措施都没有用… 抵抗力与年龄的增长成反比的下降,就像体...
    公举夜未眠阅读 197评论 0 0
  • 仉咏阅读 318评论 12 6
  • 经过商业思考,以及计算出来的巨额财富,毅然决定自己生产创可贴! 于是,借钱租厂房,借钱出差,借钱买设备,借钱...
    正午阳光CEO阅读 463评论 3 6