封装好的可设置标题、正文字体的默认样式UIAlertController

iOS8之后,主要使用UIAlertController进行信息的显示,而默认的样式使用的比较多,所以封装了一个,以方便以后使用。

这里写图片描述

调用以下函数即可:

-(void)showIntroDuction:(NSString *)title :(NSString *)showText :(NSString *)btnStr :(UIFont *)titleFont :(UIFont *) showTextFont :(UIColor *) titleColor :(UIColor *)showTextColor :(UIColor *)btnColor
{


    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:showText preferredStyle:UIAlertControllerStyleAlert];

    // 设置标题的字体
    NSMutableAttributedString *attributedStrTitle = [[NSMutableAttributedString alloc]initWithString:title];
    [attributedStrTitle addAttribute:NSFontAttributeName value:titleFont range:NSMakeRange(0, [title length])];
    [attributedStrTitle addAttribute:NSForegroundColorAttributeName value:titleColor range:NSMakeRange(0, [title length])];

    // 利用KVC赋值
    [alertController setValue:attributedStrTitle forKey:@"attributedTitle"];

    // 设置正文的字体
    NSMutableAttributedString *messageAtt = [[NSMutableAttributedString alloc] initWithString:showText];
    [messageAtt addAttribute:NSFontAttributeName value:showTextFont range:NSMakeRange(0, [showText length])];
    [messageAtt addAttribute:NSForegroundColorAttributeName value:showTextColor range:NSMakeRange(0, [showText length])];
    [alertController setValue:messageAtt forKey:@"attributedMessage"];

    // 按钮
    UIAlertAction *alertAction = [UIAlertAction actionWithTitle:btnStr style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:alertAction];
    // 按钮颜色
    [alertAction setValue:btnColor forKey:@"_titleTextColor"];


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

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值