美文网首页
AlertController的title、message和按钮

AlertController的title、message和按钮

作者: Moker_C | 来源:发表于2017-09-14 16:30 被阅读51次

    //设置message

    NSMutableAttributedString *messageStr = [[NSMutableAttributedString alloc] initWithString:@"message"];

    [messageStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,5)];

    [messageStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(0, 5)];

    [alertController setValue:messageStr forKey:@"attributedMessage"];

    [self presentViewController:alertController animated:YES completion:nil];

    //设置title

    NSMutableAttributedString *titleStr = [[NSMutableAttributedString alloc]initWithString:@"Title"];

    [titleStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,2)];

    [titleStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15]range:NSMakeRange(0,2)];

    [alertController setValue:titleStr forKey:@"attributedTitle"];

    //设置按钮颜色

    UIAlertAction:

    if (iOS9Later && [action.title isEqualToString:@"确定"] ) {

    [action setValue:[UIColor greenColor] forKey:@"titleTextColor"];

    } else {

    [action setValue:[UIColor redColor] forKey:@"titleTextColor"];

    }

    相关文章

      网友评论

          本文标题:AlertController的title、message和按钮

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