AOAlertController 1.1

AOAlertController 1.1

测试已测试
语言语言 SwiftSwift
许可协议 MIT
发布最新发布2016年4月
SPM支持 SPM

Oleg Adamov 维护。



  • Oleg Adamov

AOAlertController

AOAlertController 看起来与普通的 UIAlertController 类似,但每个操作项、标题、字体和颜色都可以自定义。

Screenshot

安装

  • CocoaPods: pod 'AOAlertController'
  • 从 Source 文件夹

使用方法

有两种方式来设置弹窗

  • AOAlertSettings 类配置为所有弹窗控制器的默认样式
  • 设置您想要创建的每个控制器

AOAlertSettings 属性

  • titleFont
  • messageFont
  • defaultActionFont
  • cancelActionFont
  • destructiveActionFont
  • backgroundColor
  • linesColor
  • titleColor
  • messageColor
  • defaultActionColor
  • destructiveActionColor
  • cancelActionColor
  • tapBackgroundToDismiss

例如:AOAlertSettings.sharedSettings.backgroundColor = UIColor.redColor() — 这意味着对于所有的 AOAlertController 实例,都将默认设置红色背景。

修改单个控制器的属性

对于单个控制器设置的属性优先级高于 AOAlertSettings 中的属性

配置

控制器样式

  • AOAlertControllerStyle.Alert
  • AOAlertControllerStyle.ActionSheet

可用的控制器属性

  • actionItemHeight
  • backgroundColor
  • linesColor
  • titleColor
  • titleFont
  • messageColor
  • messageFont
  • tapBackgroundToDismiss

示例

let alert = AOAlertController(title: "Title", message: nil, style: .Alert)
alert.titleFont = UIFont(name: "AvenirNext-Bold", size: 14)!

动作样式

  • AOAlertActionStyle.Default
  • AOAlertActionStyle.Cancel
  • AOAlertActionStyle.Destructive

可用的属性

  • color
  • font

示例

let actionCancel = AOAlertAction(title: "Cancel", style: .Cancel, handler: nil)
actionCancel.color = UIColor.orangeColor()
alert.addAction(actionCancel)

完整使用示例

let alert = AOAlertController(title: "Example Alert", message: "All in one", style: .Alert)
let action = AOAlertAction(title: "Default Action", style: .Default) {}
action.color = UIColor.blackColor()
let cancel = AOAlertAction(title: "Cancel", style: .Cancel, handler: nil)
alert.addAction(action)
alert.addAction(cancel)
self.navigationController?.presentViewController(alert, animated: false, completion: nil)