2121
2222import UIKit
2323
24+ /**
25+ View which presenting. You can configure `titleLabel`, `subtitleLabel` and other. For change duration use property `duration`.
26+ Also you can configure layout & haptic. If you use preset, all configure automatically.
27+ */
2428open class SPAlertView : UIView {
2529
30+ /**
31+ Large top text on alert.
32+ */
2633 private var titleLabel : UILabel ? = nil
34+
35+ /**
36+ Small text on alert.
37+ */
2738 private var subtitleLabel : UILabel ? = nil
39+
40+ /**
41+ Icon view. Size for it configure in `layout` property.
42+ */
2843 private var iconView : UIView ? = nil
44+
45+ /**
46+ Blur view for background.
47+ */
2948 private var backgroundView : UIVisualEffectView !
3049
50+ /**
51+ Duration time when alert visible.
52+ */
3153 public var duration : TimeInterval = 1.5
54+
55+ /**
56+ Allow dismiss by tap on alert. By default it allowed.
57+ */
3258 public var dismissByTap : Bool = true
59+
60+ /**
61+ Vibro for this alert. Default value using for presets. If you init custom. haptic not configure.
62+ */
3363 public var haptic : SPAlertHaptic = . none
64+
65+ /**
66+ Spacing and icon size configure here. Auto configure when you using presets.
67+ */
3468 public var layout = SPAlertLayout ( )
3569
70+ /**
71+ View on which present alert.
72+ */
73+ public var keyWindow : UIView = ( UIApplication . shared. keyWindow ?? UIWindow ( ) )
74+
3675 public init ( title: String , message: String ? , preset: SPAlertPreset ) {
3776 super. init ( frame: CGRect . zero)
3877 iconView = preset. iconView
@@ -117,7 +156,7 @@ open class SPAlertView: UIView {
117156 titleLabel. attributedText = NSAttributedString ( string: titleLabel. text ?? " " , attributes: [ . paragraphStyle: style] )
118157 addSubview ( titleLabel)
119158 }
120-
159+
121160 if let subtitleLabel = subtitleLabel {
122161 subtitleLabel. font = UIFont . systemFont ( ofSize: 16 )
123162 subtitleLabel. numberOfLines = 0
@@ -138,6 +177,9 @@ open class SPAlertView: UIView {
138177
139178 // MARK: - Public
140179
180+ /**
181+ Use this method for present controller. No need pass any controller, alert appear on `keyWindow`.
182+ */
141183 public func present( ) {
142184 haptic. impact ( )
143185 keyWindow. addSubview ( self )
@@ -159,6 +201,9 @@ open class SPAlertView: UIView {
159201 } )
160202 }
161203
204+ /**
205+ Use this method for force dismiss controller. By default it call automatically.
206+ */
162207 @objc func dismiss( ) {
163208 UIView . animate ( withDuration: 0.2 , animations: {
164209 self . alpha = 0
@@ -191,12 +236,18 @@ open class SPAlertView: UIView {
191236 backgroundView. frame = bounds
192237 }
193238
239+ /**
240+ Layout labels with multi-lines.
241+ */
194242 private func layout( _ label: UILabel , x: CGFloat , y: CGFloat , width: CGFloat ) {
195243 label. frame = CGRect . init ( x: x, y: y, width: width, height: 0 )
196244 label. sizeToFit ( )
197245 label. frame = CGRect . init ( x: x, y: y, width: width, height: label. frame. height)
198246 }
199247
248+ /**
249+ This menthod call when need calulate height with layout.
250+ */
200251 private func calculateHeight( ) -> CGFloat {
201252 var height : CGFloat = 0
202253 if let subtitleLabel = subtitleLabel {
@@ -213,8 +264,9 @@ open class SPAlertView: UIView {
213264 return height
214265 }
215266
216- // MARK: - Internal
217-
267+ /**
268+ Check `userInterfaceStyle` mode.
269+ */
218270 private var isDarkMode : Bool {
219271 if #available( iOS 12 . 0 , * ) {
220272 if traitCollection. userInterfaceStyle == . dark {
@@ -226,6 +278,4 @@ open class SPAlertView: UIView {
226278 return false
227279 }
228280 }
229-
230- public var keyWindow : UIView = ( UIApplication . shared. keyWindow ?? UIWindow ( ) )
231281}
0 commit comments