要求
- Xcode 8.3+
- Swift 3.2+
- iOS 9.0+
介紹
UIKit中的對(duì)話框組件:
- 一般情況下,系統(tǒng)提供了
UIAlertView
和UIAlertController
兩個(gè)類,提供了對(duì)話框的基本使用,用法比較簡(jiǎn)單,這里不再贅述; - 但系統(tǒng)的alert對(duì)話框默認(rèn)是很難自定義樣式的:比如修改文字顏色、圓角大小以及點(diǎn)擊背景自動(dòng)消失等等操作;
Dialog庫(kù)
- 本庫(kù)模仿系統(tǒng)的alert控件,實(shí)現(xiàn)了高度的還原(包括動(dòng)畫和UI),以及更友好強(qiáng)大的適配(包括轉(zhuǎn)屏、文本過長(zhǎng)、按鈕過多等情況下的UI適配);
- 本庫(kù)用法更加簡(jiǎn)潔,基于UIWindow的topViewController,任何地方中均可調(diào)用;
- 高度可定制的UI(按鈕顏色、icon、文本對(duì)齊位置、對(duì)話框的圓角大小等);
- 支持自定義view/view controller的彈出;
- 支持圖片大圖模式;
用法
default默認(rèn)樣式
- 方法定義
public static func `default`(title: Dialog.Title? = nil,
message: Dialog.Message? = nil,
actions: [Dialog.Action]? = nil,
configuration: Dialog.Configuration = .default)
{}
Dialog.Title
public init(_ text: String?,
color: UIColor = Dialog.Configuration.default.primaryColor,
alignment: NSTextAlignment = .center)
{}
Dialog.Message
public init(_ text: String?,
attributes: [String: Any] = [:])
{}
Dialog.Action
public init(title: String? = nil, icon: UIImage? = nil, style: Action.Style = .default, handler: Handler? = nil)
{}
Dialog.Configuration
public class Configuration: NSObject {
public var cornerRadius: CGFloat = 0 //圓角半徑
public var isBackgroundViewUserInteractionEnabled = false //是否點(diǎn)擊背景消失
public var primaryColor: UIColor = .black //對(duì)話框里的元素主色
}
- 用法示例
Dialog Default
代碼見
DemoDialogDefaultVC.swift
image大圖樣式
Dialog.image(UIImage(named: "image"), actions: [
Dialog.Action(title: "hello1"),
Dialog.Action(title: "hello1"),
Dialog.Action(title: "hello1"),
Dialog.Action(title: "hello1"),
Dialog.Action(title: "hello1"),
Dialog.Action(title: "hello1")
])
Dialog Image
custom自定義view樣式
// 自定義controller
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ActionCollectionVC") as! ActionCollectionVC
vc.view.frame = CGRect(origin: .zero, size: CGSize(width: view.bounds.width, height: 100))
vc.collectionView?.delegate = self
// 調(diào)用
Dialog.custom(vc.view, actions: [
Dialog.Action(title: "Cancel")
])
Dialog Custom
Carthage
- 目前該控件庫(kù)已上傳到github上,支持Carthage編譯
- 用法
1.在你的Cartfile中加入
github "BackWorld/Dialog" "master"
2.在終端執(zhí)行
carthage update
3.將
Carthage/Build/iOS
目錄下的Dialog.framework
拖到你的項(xiàng)目中
4.在使用的swift文件中
import Sheeter
即可
Github
https://github.com/BackWorld/Dialog
如果對(duì)你有幫助,別忘了點(diǎn)個(gè)贊和關(guān)注~