Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. open class VKPopupView: NSObject
  2. {
  3. // MARK: Public properties
  4.  
  5. /// Title of the `VKPopupView`. Appears above the contentView
  6. open var title: String?
  7.  
  8. /// Content you want to display inside popup
  9. /// - Important: Max size of the contentView is `300x300`.
  10. /// - requires: `VKPopupView` will reset backgroundColor to `UIColor.clear`. It is done in order to match Apple's style
  11. open var contentView: UIView?
  12. {
  13. didSet
  14. {
  15. if let oldContent = oldValue
  16. {
  17. oldContent.removeFromSuperview()
  18. }
  19.  
  20. if contentView != nil
  21. {
  22. self.adoptContentView()
  23. }
  24. }
  25. }
  26.  
  27. /// Set background blur style
  28. /// - Note: Default is `UIBlurEffectStyle.light`
  29. open var backgroundBlurStyle: UIBlurEffectStyle = .light
  30. {
  31. didSet
  32. {
  33. self.viewOverlay.effect = UIBlurEffect(style: backgroundBlurStyle)
  34. }
  35. }
  36.  
  37. /// Set popup blur style
  38. /// - Note: Default is `UIBlurEffectStyle.extraLight`
  39. open var contentViewBlurStyle: UIBlurEffectStyle = .extraLight
  40. {
  41. didSet
  42. {
  43. self.containerView.effect = UIBlurEffect(style: contentViewBlurStyle)
  44. }
  45. }
  46.  
  47.  
  48. /// Delegate of the VKPopupView
  49. open var delegate: VKPopupViewDelegate?
  50.  
  51. /// Set the animation duration for show and hide
  52. /// - Note: Default is `0.4` seconds
  53. open var animationSpeed: TimeInterval = 0.4
  54.  
  55. /// Constant of the content frame
  56. /// - Attention: Please use it as constant for all your content views
  57. open static let contentFrame = CGRect(x: 0, y: 0, width: 300, height: 300)
  58.  
  59. // MARK: Private properties
  60. // Views
  61.  
  62. /// Background overlay view
  63. fileprivate var viewOverlay = UIVisualEffectView()
  64.  
  65. /// Container of the content view
  66. fileprivate var containerView = UIVisualEffectView()
  67.  
  68. /// Title label
  69. /// - Note: It will not show up in `title` is `nil`
  70. fileprivate var labelTitle = UILabel()
  71.  
  72. // Sizes
  73. /// Initial frame from where `VKPopupView` will fade in and fade out
  74. fileprivate var initialFrame: CGRect!
  75.  
  76. /// Default frame which is used when `initialFrame` is `nil`
  77. fileprivate var zeroFrame = CGRect(x: UIScreen.main.bounds.midX, y: UIScreen.main.bounds.midY, width: 0, height: 0)
  78.  
  79. /// Frame used when `VKPopupView` is shown
  80. fileprivate lazy var finalFrame: CGRect =
  81. {
  82. var size: CGFloat = 300
  83. let x: CGFloat = self.viewOverlay.bounds.midX - size / 2
  84. let y: CGFloat = self.viewOverlay.bounds.midY - size / 2
  85.  
  86. return CGRect(x: x, y: y, width: size, height: size)
  87. }()
  88.  
  89. // MARK: Init
  90.  
  91. /// Init VKPopupView and set 'backgrundStyle' and 'contentViewStyle' properties
  92. ///
  93. /// - Parameters:
  94. /// - backgroundStyle: Set 'backgroundStyle' value
  95. /// - contentViewStyle: Set 'contentViewStyle' value
  96. ///
  97. /// Example:
  98. ///
  99. /// let popup = VKPopup(backgroundStyle: .dark, contentViewStyle: .light)
  100. /// ___
  101. public convenience init(backgroundStyle: UIBlurEffectStyle = .light, contentViewStyle: UIBlurEffectStyle = .extraLight)
  102. {
  103. self.init()
  104. self.backgroundBlurStyle = backgroundStyle
  105. self.contentViewBlurStyle = contentViewStyle
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement