zoukankan      html  css  js  c++  java
  • Swift 封装AleartController

    import UIKit
    
    
    class Healp: NSObject {
     //alertController title message messageAlignment message对齐方式 messageLineSpacing文字行间距  messgageFont message字体大小 sureText确认按钮文字 sureColor确认按钮颜色 canclText取消文字cancleColor取消字体颜色 vc 所在控制器 sureAction点击方法  canclAction取消点击方法
        class func customAlertC(title:String , message:String ,messageColor:UIColor ,messageAlignment:NSTextAlignment ,messageLineSpacing:CGFloat ,messgageFont:CGFloat  , sureText:String , sureColor:UIColor , canclText:String ,  cancleColor:UIColor ,  vc:UIViewController ,sureAction:@escaping (_ sure :UIAlertAction ) -> () , canclAction :@escaping (_ cancle:UIAlertAction) ->()){
            
            
            let  aleartC = UIAlertController (title:title , message:message , preferredStyle:UIAlertControllerStyle.alert)
            /*
             设置message行间距 对齐方式  字体大小 字体颜色
             */
            
            let   paragraphStyle = NSMutableParagraphStyle ()
            paragraphStyle.alignment = messageAlignment
            paragraphStyle.lineSpacing = messageLineSpacing
            
            let attributes : NSDictionary = [ NSFontAttributeName : UIFont .systemFont(ofSize: messgageFont) , NSParagraphStyleAttributeName:paragraphStyle , NSForegroundColorAttributeName:messageColor]
            let mutableString = NSAttributedString(string:message , attributes:attributes as? [String : Any])
            aleartC .setValue(mutableString, forKey: "attributedMessage")
            
            
            
            /*
             let   sureAction  = UIAlertAction (title:sureText , style:UIAlertActionStyle.destructive) {(UIAlertAction)-> Void in
     
                  sureAction (UIAlertAction)
             }
             let   cancleAction  = UIAlertAction (title:canclText , style:UIAlertActionStyle.cancel) {(UIAlertAction)-> Void in
     
                 canclAction (UIAlertAction)
             }
             */
            
            //上两句和下边这两句作用相同
            //确定按钮
            let  sureAction   = UIAlertAction (title:sureText ,style:UIAlertActionStyle.default ,handler:sureAction)
            sureAction .setValue(sureColor, forKey: "_titleTextColor")
            
            //取消按钮
            let  cancleAction = UIAlertAction (title:canclText ,style:UIAlertActionStyle.cancel ,handler:canclAction)
             cancleAction .setValue(cancleColor, forKey: "_titleTextColor")
        
            
            aleartC.addAction(sureAction)
            aleartC.addAction(cancleAction)
            
            vc.present(aleartC,animated:true,completion:nil)
        }
    
    
    }

    调用

      Healp .customAlertC(title: "提示", message: "哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈",messageColor:UIColor.blue ,messageAlignment:NSTextAlignment.center ,messageLineSpacing:7 ,messgageFont:14  , sureText: "确定", sureColor:UIColor.red  , canclText: "取消", cancleColor: UIColor.green, vc: self, sureAction: { (action) in
                 print("确定")
            }) { (action) in
                print("取消")
    
            }
  • 相关阅读:
    面向对象编程技术的总结和理解(c++)
    对类的理解(c++)
    对指针和引用的理解(c++)
    3DES对称加密算法(ABAP 语言实现版)
    org.springframework.util.Base64Utils线程安全问题
    SAP传输请求自动发布
    ABAP WB01 BDC ”No batch input data for screen & &“ ”没有屏幕 & & 的批输入数据“
    SAP S/4 1610 IDES + HANA 2.0 安装
    ABAP语言实现 左移 <<、无符号右移 >>> 位移操作
    ABAP表抛FTP通用程序
  • 原文地址:https://www.cnblogs.com/Lrx-lizi/p/7300539.html
Copyright © 2011-2022 走看看