dillidon /alerts-and-pickers
Advanced usage of UIAlertController and pickers based on it: Telegram, Contacts, Location, PhotoLibrary, Country, Phone Code, Currency, Date...
★ 5,756⑂ 696👁 100⑃ 28● 91▤ 0
+0
日增长
5,756
stars
696
forks
100
watchers
28
prs
91
issues
0
releases
README
Alerts & Pickers
Advanced usage of native UIAlertController with TextField, TextView, DatePicker, PickerView, TableView, CollectionView and MapView.
Features
- [x] Custom pickers based on UITextField, UITextView, UIDatePicker, UIPickerView, UITableView, UICollectionView and MKMapView.
- [x] Example using a Storyboard.
- [x] Easy contentViewController placement.
- [x] Attributed title label and message label.
- [x] Button customization: image and title color.
- [x] Understandable action button placement.
- [x] Easy presentation.
- [x] Pure Swift 4.
Usage
- New Alert
swift
let alert = UIAlertController(style: .alert, title: "Title", message: "Message")
// or
let alert = UIAlertController(style: .alert)
- Set and styling title
swift
alert.set(title: "Title", font: .systemFont(ofSize: 20), color: .black)
// or
alert.setTitle(font: .systemFont(ofSize: 20), color: .black)
- Set and styling message
swift
alert.set(message: "Message", font: .systemFont(ofSize: 16), color: .black)
// or
alert.setMessage(font: .systemFont(ofSize: 16), color: .black)
- Add button with image
swift
alert.addAction(image: image, title: "Title", color: .black, style: .default) { action in
// completion handler
}
Show Alert
swift
// show alert
alert.show()
// or show alert with options
alert.show(animated: true, vibrate: true) {
// completion handler
}
Set Content ViewController
When setting your own custom UIViewController into UIAlertController keep in mind to set prefferedContentSize.height of the controller otherwise it will no effect. You can not set prefferedContentSize.width.
swift
let alert = UIAlertController(style: .alert, title: "Title")
let vc = CustomViewController()
vc.preferredContentSize.height = height
alert.setValue(vc, forKey: "contentViewController")
alert.show()
// or
let alert = UIAlertController(style: .alert, title: "Title")
let vc = CustomViewController()
alert.set(vc: vc, height: height)
alert.show()
Pickers
For UX better to use .actionSheet style in UIAlertController when set picker into contentViewController. If you like you can use .alert style as well, buy .actionSheet style is wider and User can see more as well as action button is placing at bottom that also more convenience for User to touch it.
UITextField
In native UIAlertController you can only add UITextField to .alert style with default style and you can not change such properties as .borderColor, .borderWidth, .frame.size and so on. But if you make your own UIViewController with UITextField, it will solve all these problems.
One TextField Picker
You can use both styles .alert and .actionSheet of UIAlertController.
swift
let alert = UIAlertController(style: self.alertStyle, title: "TextField")
let config: TextField.Config = { textField in
textField.becomeFirstResponder()
textField.textColor = .black
textField.placeholder = "Type something"
textField.left(image: image, color: .black)
textFielTop issues
#13Installation via CocoaPods19 comments · 2018-01-22#37iOS 10.0 compatibility8 comments · 2018-04-17#4When integrated pod8 comments · 2018-01-15#98Update to swift 57 comments · 2019-11-21#33DatePicker and PickerView issues.7 comments · 2018-03-26#73Getting error In swift 4.2 6 comments · 2019-01-14#69Time for semi-official fork?6 comments · 2018-11-06#46Installation via CocoaPods needed6 comments · 2018-06-22