ios开发框架封装(十一):UIAlertController封装

63 阅读1分钟

先放demo地址:github.com/KeWangKW/99…

  • 减少代码量,一句代码调用
  • 封装文件:Alert.swfit
  • 示例代码文件:AlertUseShow.swift

屏幕录制2023-07-11 13.45.27.gif

    1. 文本提醒框, 单个按钮无响应事件
    • @objc static func showText(_ title: String?, _ message: String? = nil)
    • 调用:
      • Alert.showText("233" ,"33333333")
      • [Alert showText:@"233" :@"33333333"];
    1. 文本提醒框,单个按钮带响应事件
    • @objc static func showOnly(_ title: String?, _ message: String?, _ enter: String, enterHandle: (() -> Void)?)
    • 调用:
      • Alert.showOnly("233", "3333333", "ok") {}
      • [Alert showOnly:@"233" :@"3333333" :@"ok" enterHandle:^{}
    1. 文本提醒框,双按钮,单个响应事件
    • @objc static func showSingle(_ title: String?, _ message: String?, _ enter: String, _ cancel: String?, _ enterHandle: (() -> Void)?)
    • 调用:
      • Alert.showSingle("233", "3333333", "ok", "cancel") {}
      • [Alert showSingle:@"3333333" :@"3333333" :@"ok" :@"cancel" :^{}
    1. 文本提醒框,双按钮响应事件
    • @objc static func showDouble(_ title: String?, _ message: String?, _ enter: String, _ cancel: String?, _ enterHandle: (() -> Void)?, _ cancelHandle: (() -> Void)?)
    • 调用:
      • Alert.showDouble("233", "3333333", "ok", "cancel") {} _: {}
      • [Alert showDouble:@"233" :@"3333333" :@"ok" :@"cancel" :^{} :^{}];
    1. 自定义初始化UIAlertController <多按钮>
    • @objc static func AlertController(title: String?, message: String?, cancel: String?, buttonTitles: [String]?, completion: ((Int) -> Void)? = nil, cancelAction: (() -> Void)? = nil)
    • 调用:
      • Alert.AlertController(title: "233", message: "33333", cancel: "cancel", buttonTitles: ["哈哈","哦哦","呵呵"]) { selectedIdx in } cancelAction: {}
      • [Alert AlertControllerWithTitle:@"233" message:@"33333" cancel:@"cancel" buttonTitles:@[@"哈哈", @"哦哦", @"呵呵"] completion:^(NSInteger selectedIdx) {} cancelAction:^{}];
    1. 自定义初始化UIAlertController <多按钮>
    • @objc static func AlertControllerSheet(title: String?, message: String?, cancel: String?, buttonTitles: [String]?, completion: ((Int) -> Void)? = nil, cancelAction: (() -> Void)? = nil)
    • 调用:
      • Alert.AlertControllerSheet(title: "233", message: "33333", cancel: "cancel", buttonTitles: ["哈哈","哦哦","呵呵"]) { selectedIdx in } cancelAction: {}
      • [Alert AlertControllerSheetWithTitle:@"233" message:@"33333" cancel:@"cancel" buttonTitles:@[@"哈哈", @"哦哦", @"呵呵"] completion:^(NSInteger selectedIdx) {} cancelAction:^{}];