项目作者: hryk224

项目描述 :
Swift AlertController with UIVisualeffectview
高级语言: Swift
项目地址: git://github.com/hryk224/PCLBlurEffectAlert.git
创建时间: 2015-10-12T12:03:48Z
项目社区:https://github.com/hryk224/PCLBlurEffectAlert

开源协议:MIT License

下载


PCLBlurEffectAlert

Swift AlertController, use UIVisualeffectview

Cocoapods Compatible
Swift 3.0

Requirements

  • iOS 8.0+
  • Swift 3.0+
  • ARC

Feature

  • Change color
  • Change effect
  • Change font
  • Use UITextField
  • Use UIImageView

install

Cocoapods

Adding the following to your Podfile and running pod install:

  1. use_frameworks!
  2. pod "PCLBlurEffectAlert"

import

  1. import PCLBlurEffectAlert

Initialize

UIBlurEffect

  1. // Default effect: UIBlurEffect(style: .extraLight)
  2. convenience init(title: String?, message: String?, effect: UIBlurEffect, style: PCLBlurEffectAlert.ControllerStyle)

style => alert, alertVertical, actionSheet

When actions count becomes more than 3, alert and alertVertical is the same as.

Usage

Example

  1. let alertController = PCLBlurEffectAlertController(title: "How are you doing?",
  2. message: "Press a button!",
  3. effect: UIBlurEffect(style: .lightdark)
  4. style: .alert)'
  5. // Customize if needed
  6. alertController.configure(titleColor: .white)
  7. alertController.configure(buttonFont: [.default: UIFont.systemFont(ofSize: 24),
  8. .destructive: UIFont.boldSystemFont(ofSize: 20),
  9. .cancel: UIFont.systemFont(ofSize: 14)])
  10. // Adds ImageView
  11. alertController.addImageView(with: <image files>)
  12. // Adds TextField
  13. alertController.addTextField()
  14. // Adds actions
  15. let action = PCLBlurEffectAlertAction(title: "I’m fine.", style: .default) { _ in }
  16. let cancelAction = PCLBlurEffectAlertAction(title: "Not so good.", style: .cancel) { _ in }
  17. alertController.addAction(action)
  18. alertController.addAction(cancelAction)
  19. // Presented
  20. alertController.show() // or present(alertController, animated: true, completion: nil)

Sources

  1. // Adds Actions
  2. open func addAction(_ action: PCLBlurEffectAlertAction)
  3. // Adds ImageView
  4. open func addImageView(with image: UIImage, configurationHandler: ((UIImageView?) -> Void)? = nil)
  5. // Adds TextFields
  6. open func addTextField(with configurationHandler: ((UITextField?) -> Void)? = nil)
  7. // Presented
  8. open func show()

Customize

  1. // Default ActionSheet: UIScreen.main.bounds.width - (margin * 2)
  2. // Default Alert: 320 - (margin * 2)
  3. func configure(alertViewWidth: CGFloat)
  4. // Default: 4
  5. func configure(cornerRadius: CGFloat)
  6. // Default: 1 / UIScreen.main.scale
  7. func configure(thin: CGFloat)
  8. // Default: 8
  9. func configure(margin: CGFloat)
  10. /// Color
  11. // Default: UIColor.black.withAlphaComponent(0.3)
  12. func configure(overlayBackgroundColor: UIColor)
  13. // Default: .clear
  14. func configure(backgroundColor: UIColor)
  15. /// Text
  16. // Default: .boldSystemFont(ofSize: 16)
  17. // Default: .black
  18. func configure(titleFont: UIFont, titleColor: UIColor)
  19. // Default: .systemFont(ofSize: 14)
  20. // Default: .black
  21. func configure(messageFont: UIFont, messageColor: UIColor)
  22. // Default:
  23. // .default: UIFont.systemFont(ofSize: 16),
  24. // .cancel: UIFont.systemFont(ofSize: 16),
  25. // .destructive: UIFont.systemFont(ofSize: 16)
  26. func configure(buttonFont: [PCLBlurEffectAlert.ActionStyle : UIFont])
  27. // Default:
  28. // .default: .black,
  29. // .cancel: .black,
  30. // .destructive: .red
  31. func configure(buttonTextColor: [PCLBlurEffectAlert.ActionStyle : UIColor])
  32. // Default:
  33. // .default: .gray,
  34. // .cancel: .gray,
  35. // .destructive: .gray
  36. func configure(buttonDisableTextColor: [PCLBlurEffectAlert.ActionStyle : UIColor])
  37. /// Button
  38. // Default: 44
  39. func configure(buttonHeight: CGFloat)
  40. // Default: .clear
  41. func configure(buttonBackgroundColor: UIColor)
  42. // Default: 32
  43. func configure(textFieldHeight: CGFloat)
  44. // Default: UIColor.white.withAlphaComponent(0.1)
  45. func configure(textFieldsViewBackgroundColor: UIColor)
  46. // Default: UIColor.black.withAlphaComponent(0.15)
  47. func configure(textFieldBorderColor: UIColor)

More Examples

  1. let alertController = PCLBlurEffectAlertController(title: "How are you doing?",
  2. message: "Press a button!",
  3. style: .alert)
  4. let action1 = PCLBlurEffectAlertAction(title: "I’m fine.", style: .default) { _ in }
  5. let action2 = PCLBlurEffectAlertAction(title: "Not so good.", style: .default) { _ in }
  6. alertController.addAction(action1)
  7. alertController.addAction(action2)
  8. alertController.show()

  1. let alertController = PCLBlurEffectAlertController(title: "title title title title title title title",
  2. message: "message message message message message",
  3. effect: UIBlurEffect(style: .light),
  4. style: .alert)
  5. alertController.addTextField { _ in }
  6. alertController.addTextField { _ in }
  7. alertController.configure(textFieldsViewBackgroundColor: UIColor.white.withAlphaComponent(0.1))
  8. alertController.configure(textFieldBorderColor: .black)
  9. alertController.configure(buttonDisableTextColor: [.default: .lightGray, .destructive: .lightGray])
  10. let action1 = PCLBlurEffectAlertAction(title: "Default", style: .default) { _ in }
  11. let action2 = PCLBlurEffectAlertAction(title: "Destructive", style: .destructive) { _ in }
  12. let cancelAction = PCLBlurEffectAlertAction(title: "Cancel", style: .cancel) { _ in }
  13. alertController.addAction(action1)
  14. alertController.addAction(action2)
  15. alertController.addAction(cancelAction)
  16. alertController.show()

  1. let alertController = PCLBlurEffectAlertController(title: "How are you doing?",
  2. message: "Press a button!",
  3. effect: UIBlurEffect(style: .dark),
  4. style: .actionSheet)
  5. let action1 = PCLBlurEffectAlertAction(title: "I’m fine.", style: .default) { _ in }
  6. let action2 = PCLBlurEffectAlertAction(title: "Not so good.", style: .default) { _ in }
  7. alertController.addAction(action1)
  8. alertController.addAction(action2)
  9. alertController.show()

  1. let alertController = PCLBlurEffectAlertController(title: "title title title title title title title",
  2. message: "message message message message message",
  3. style: .actionSheet)
  4. alertController.addTextField()
  5. alertController.addTextField()
  6. alertController.configure(textFieldsViewBackgroundColor: UIColor.white.withAlphaComponent(0.1))
  7. alertController.configure(textFieldBorderColor: .black)
  8. alertController.configure(buttonDisableTextColor: [.default: .lightGray, .destructive: .lightGray])
  9. let action1 = PCLBlurEffectAlertAction(title: "Default", style: .default) { _ in }
  10. let action2 = PCLBlurEffectAlertAction(title: "Destructive", style: .destructive) { _ in }
  11. let cancelAction = PCLBlurEffectAlertAction(title: "Cancel", style: .cancel) { _ in }
  12. alertController.addAction(action1)
  13. alertController.addAction(action2)
  14. alertController.addAction(cancelAction)
  15. alertController.show()

  1. let alertController = PCLBlurEffectAlertController(title: "title title title title title title title",
  2. message: "message message message message message",
  3. style: .alert)
  4. alertController.addImageView(with: UIImage(named: "cat")!)
  5. let catAction = PCLBlurEffectAlertAction(title: "Cat?", style: .default) { _ in
  6. print("You pressed Cat?")
  7. }
  8. let dogAction = PCLBlurEffectAlertAction(title: "Dog?", style: .default) { _ in
  9. print("You pressed Dog?")
  10. }
  11. alertController.addAction(catAction)
  12. alertController.addAction(dogAction)
  13. alertController.show()

Photos from

Acknowledgements

License

This project is made available under the MIT license. See LICENSE file for details.