关于弹窗(UIAlerterViewController)的总结

当在一个多次要用到弹窗的时候,我们会觉得很麻烦每次都重写。于是自己创建一个单独的类来重写这个关于弹窗的方法,再用到的时候我们只需要倒入头文件,调用这个方法即可,比较方便。下面是一个小方法。

   #import "Alert.h"

   @implementation Alert

    +(void)alert:(NSString *)str andUIviewController:(UIViewController *)v completion:(void (^ )               (void))completion{

     UIAlertController *a =[UIAlertController alertControllerWithTitle:@"友情提示" message:str                preferredStyle:UIAlertControllerStyleAlert];

       UIAlertAction *ac =[UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault                handler:nil];

        [a addAction:ac];

        [v presentViewController:a animated:YES completion:completion];

         }

         @end

修改title和message的字体颜色和大小

     //修改title 

   NSString* titleStr =@"提示";

    NSMutableAttributedString *alertControllerStr = [[NSMutableAttributedString alloc]                          initWithString:titleStr];

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

    [alertControllerStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17]            range:NSMakeRange(0, titleStr.lenth)];

   if (alertController valueForKey:@"attributedTitle") {

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

   }

//修改message

 NSString* messegeStr =@"提示内容";

 NSMutableAttributedString *alertControllerMessageStr = 

 [[NSMutableAttributedString alloc] initWithString:messegeStr];

 [alertControllerMessageStr addAttribute:NSForegroundColorAttributeName value:[UIColor              greenColor] range:NSMakeRange(0, messegeStr.lenth)]; 

  [alertControllerMessageStr addAttribute:NSFontAttributeName value:[UIFont                                  systemFontOfSize:20] range:NSMakeRange(0, messegeStr.lenth)];

   if (alertController valueForKey:@"attributedMessage") {

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

    }
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 11,858评论 0 17
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,034评论 25 709
  • 这样和世界相处 怎么样对待自卑,家庭对一个孩子有什么样的影响,怎么培养社会兴趣,怎么样融入社会。 第一部分:我们和...
    一枚冰儿阅读 2,726评论 7 2
  • 诗人, 你的眼中燃烧着五月的太阳 你的阳光使黑暗中的邪恶瑟缩 你的天籁般的声音,淡去了我们的耳鸣 你拯救了人的灵魂...
    巴尔扎克的星空阅读 4,177评论 0 1
  • 凌晨的浦东机场依旧喧嚣 晚点的,临飞的,心情不一 还有20min登机,开个树洞吐吐一路的心情 选这个地方去旅行,似...
    熊猫大的黑眼圈阅读 2,656评论 0 0

友情链接更多精彩内容