美文网首页
关于弹窗(UIAlerterViewController)的总结

关于弹窗(UIAlerterViewController)的总结

作者: __Seven | 来源:发表于2018-04-04 10:17 被阅读13次

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

   #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"];

    }

相关文章

  • 关于弹窗(UIAlerterViewController)的总结

    当在一个多次要用到弹窗的时候,我们会觉得很麻烦每次都重写。于是自己创建一个单独的类来重写这个关于弹窗的方法,再用到...

  • 关于弹窗Dialog,Toast,PopupWindow,Sna

    关于弹窗Dialog,Toast,PopupWindow,SnackBar总结分析目录介绍:0.关于弹窗概述1.关...

  • 弹与不弹

    在产品设计中遇到关于是弹窗还是页面的选择问题,在网上查找了一些资料,加上我自己的理解,总结一下。 弹窗的特点 可将...

  • 2016.09.01第一次用简书(收藏)

    今天在腾讯ISUX看到关于弹窗的文章,受益匪浅,谢谢前辈的总结。 https://isux.tencent.com...

  • APP页面提示样式小总结

    最近做交互总结,又碰到了页面弹窗提示的问题,于是便总结了下。 我按弹窗提示的样式分为了以下几种来进行说明。每种样式...

  • APP弹窗的分类及设计技巧

    刷了很多文章,看到各式各样的弹窗分类,今天总结一下。 什么是弹窗? 弹窗又称为对话框,是App与用户进行交互的常见...

  • iOS 关于UIAlertController、UIAlertV

    关于UIAlertController弹窗问题 目标:同时弹出2个以上的弹窗 问题:在弹出一个alertContr...

  • Android输入法覆盖App弹窗问题

    最近项目需求用到弹窗,但是在弹窗里有EditText,从而引发系统输入法覆盖弹窗的问题,值此记录下。 网上很多关于...

  • 弹窗总结ing

    今天来聊一聊 产品设计 各环节中必不可少的元素【模态弹框】和【非模态弹框】 一、相关定义 模态弹窗:打断用户流程,...

  • Appium-处理系统弹窗

    前言: 最近在搞appium自动化,iOS的系统弹窗是大家都会遇到的,本文来总结处理这种弹窗的用法。 环境: Ma...

网友评论

      本文标题:关于弹窗(UIAlerterViewController)的总结

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