美文网首页
修改UIAlertController的title 、messa

修改UIAlertController的title 、messa

作者: 一生谦卦 | 来源:发表于2018-01-30 19:12 被阅读0次

    很简单!!!

    -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"嘿嘿嘿" message:@"修改你的字体颜色和大小" preferredStyle:UIAlertControllerStyleAlert];
    //修改标题的内容,字号,颜色。使用的key值是“attributedTitle”
    NSMutableAttributedString *attrTitleStr = [[NSMutableAttributedString alloc]initWithString:@"嘿嘿嘿"];
    [attrTitleStr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName:[UIColor greenColor]} range:NSMakeRange(0, attrTitleStr.length)];
    [alertController setValue:attrTitleStr forKey:@"_attributedTitle"];
    
    NSMutableAttributedString *attrMessageStr = [[NSMutableAttributedString alloc]initWithString:@"修改你的字体颜色和大小"];
    [attrMessageStr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName:[UIColor greenColor]} range:NSMakeRange(0, attrMessageStr.length)];
    [alertController setValue:attrMessageStr forKey:@"_attributedMessage"];
    
    
    
    //修改按钮的颜色 使用的key值可以使_titleTextColor
    UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"default" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [defaultAction setValue:[UIColor blueColor] forKey:@"_titleTextColor"];
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [cancelAction setValue:[UIColor yellowColor] forKey:@"_titleTextColor"];
    
    [alertController addAction:defaultAction];
    [alertController addAction:cancelAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
    

    }

    好 我们看一下效果


    Simulator Screen Shot - iPhone 8 Plus - 2018-01-30 at 19.07.35.png

    相关文章

      网友评论

          本文标题:修改UIAlertController的title 、messa

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