iOS技术点

iOS开发笔记-30: UIAlertController (A

2017-04-10  本文已影响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

上一篇 下一篇

猜你喜欢

热点阅读