SimpleAlertController 0.3.0

SimpleAlertController 0.3.0

测试已测试
语言语言 SwiftSwift
许可协议 MIT
发布最后发布2017年1月
SwiftSwift 版本3.0
SPM支持 SPM

ton-katsu 维护。



  • ton-katsu

Simple Alert Controller

非常简单的弹窗控制器。

API 类似于 UIAlertController,与 iOS 8+ 兼容

Movie

类参考

SimpleAlertController (UIAlertController)

创建一个弹窗控制器

public convenience init(title titleText: String?,
                 message messageText: String?)

public convenience init(title titleText: String?,
                 message messageText: String?,
                 colorScheme: SimpleAlertColorScheme)

控制器的属性

backgroundColor: UIColor!
alertTableColor: UIColor!
textColor: UIColor?

SimpleAlertAction (UIAlertAction)

创建一个弹窗操作

public init(title: String,
     style: SimpleAlertActionStyle,
     handler: (() -> Void)?)

操作属性

title: String
style: SimpleAlertActionStyle
handler: (() -> Void)?
buttonColor: UIColor?
buttonTextColor: UIColor?

SimpleAlertActionStyle (UIAlertActionStyle)

enum SimpleAlertActionStyle: Int {
    case Default
    case Cancel
    case Destructive
}

用法

使用颜色方案

设置颜色方案。

enum SimpleAlertColorScheme

  • Cloud
  • Lime
  • Ocean
  • Peach
let alert = SimpleAlertController(title: "SimpleAlert", message: "It's simple!", colorScheme: SimpleAlertColorScheme.Peach)

let cancel = SimpleAlertAction(title: "Cancel", style: SimpleAlertActionStyle.Cancel, handler: {() -> Void in print("cancel")})
let move = SimpleAlertAction(title: "Move", style: SimpleAlertActionStyle.Default, handler: {() -> Void in print("moved")})
let destructive = SimpleAlertAction(title: "Destructive", style: SimpleAlertActionStyle.Destructive, handler: nil)

alert.addAction(move)
alert.addAction(destructive)
alert.addAction(cancel)

simplePresentViewController(alert, animated: true)

自定义颜色

设置弹窗视图的颜色。

  • backgroundColor
  • alertTableColor
  • textColor

设置按钮颜色

  • buttonColor
  • buttonTextColor
let alert = SimpleAlertController(title: "Pop color", message: "custom color alert")
alert.backgroundColor = UIColor(red: 255/255, green: 90/255, blue: 211/255, alpha: 0.7)
alert.alertTableColor = UIColor(red: 51/255, green: 188/255, blue: 255/255, alpha: 1.0)
alert.textColor = UIColor.whiteColor()

let move = SimpleAlertAction(title: "Move", style: SimpleAlertActionStyle.Default, handler: {() -> Void in self.tabBarController?.selectedIndex = 2})
move.buttonColor = UIColor(red: 100/255, green: 255/255, blue: 165/255, alpha: 1.0)
move.buttonTextColor = UIColor.whiteColor()

let destructive = SimpleAlertAction(title: "Destrctive", style: SimpleAlertActionStyle.Destructive, handler: nil)
destructive.buttonColor = UIColor(red: 193/255, green: 255/255, blue: 6/255, alpha: 1.0)
destructive.buttonTextColor = UIColor.redColor()

let cancel = SimpleAlertAction(title: "Cancel", style: SimpleAlertActionStyle.Cancel, handler: {() -> Void in print("Canceled")})
cancel.buttonColor = UIColor.whiteColor()
cancel.buttonTextColor = UIColor(red: 51/255, green: 188/255, blue: 255/255, alpha: 1.0)


alert.addAction(move)
alert.addAction(destructive)
alert.addAction(cancel)
tabBarController?.simplePresentViewController(alert, animated: true)

仅菜单

nil 在标题和信息中。

let alert = SimpleAlertController(title: nil, message: nil, colorScheme: SimpleAlertColorScheme.Peach)

let move = SimpleAlertAction(title: "Move", style: SimpleAlertActionStyle.Default, handler: {() -> Void in self.tabBarController?.selectedIndex = 2})
let destructive = SimpleAlertAction(title: "Destrctive", style: SimpleAlertActionStyle.Destructive, handler: nil)
let cancel = SimpleAlertAction(title: "Cancel", style: SimpleAlertActionStyle.Cancel, handler: {() -> Void in print("Canceled")})

alert.addAction(move)
alert.addAction(destructive)
alert.addAction(cancel)
tabBarController?.simplePresentViewController(alert, animated: true)

安装

要求

  • iOS 8.0+
  • Swift 3

许可协议

The MIT License (MIT)

Copyright (c) 2015 ton-katsu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.