WTAlertController是一个基于Swift开发的Alert UI。基于iOS原生的UIAlertController功能进行封装,并提供了其他自定义样式的接口,扩展灵活,能让App快速创建自己想要的样式。
- 基于纯Swift开发
- 支持UIAlertController样式
- 支持横屏和竖屏
- 支持修改相关展示样式
- 支持自定义样式
- iOS 11.0+
- Xcode 13.0+
- Swift 5.5+
把这个添加到 Podfile
并更新依赖:
pod 'WTAlertController'
添加Package
dependencies: [
.Package(url: "https://github.com/Sean-LWT/Alert.git")
]
Sources/WTAlertController/ 将此目录下的文件拷贝到项目中即可
在需要的地方导入 WTAlertController
import WTAlertController
let alert = WTAlertController.init(title: "标题", message: "内容", preferredStyle: .actionSheet)
alert.addAction(.init(title: "取消", style: .cancel))
alert.addAction(.init(title: "确定", style: .default))
self.present(alert, animated: true)
// titleView
alert.addTitleViews { width in
let customView = UILabel.init(frame: .init(x: 0, y: 0, width: width, height: 59))
customView.numberOfLines = 0
customView.attributedText = .init(string: "我是一个自定义的titleView\n😄你想放什么都可以啊", attributes: [.font: UIFont.systemFont(ofSize: 16), .foregroundColor: UIColor.red])
customView.textAlignment = .center
return customView
}
// action
alert.addAction(.init(style: .default, customBlock: { width in
let customView = UIButton.init(type: .custom)
customView.frame = .init(origin: .zero, size: .init(width: width, height: 80))
customView.backgroundColor = .systemOrange
customView.setAttributedTitle(.init(string: "我是一个自定义的选项", attributes: [.font: UIFont.systemFont(ofSize: 16), .foregroundColor: UIColor.blue]), for: .normal)
return customView
}))
var config = WTAlertConfig.default
config.cornerRadius = 10
// 其他样式
...
WTAlertConfig.default = config
MIT License