美文网首页iOS技术点
iOS开发笔记-30: UIAlertController (A

iOS开发笔记-30: UIAlertController (A

作者: 原味蛋炒饭 | 来源:发表于2017-04-10 15:23 被阅读10次
    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

    相关文章

      网友评论

        本文标题:iOS开发笔记-30: UIAlertController (A

        本文链接:https://www.haomeiwen.com/subject/txwsattx.html