@@ -59,6 +59,15 @@ open class AABlurAlertController: UIViewController {
59
59
60
60
open var blurEffectStyle : UIBlurEffectStyle = . light
61
61
open var imageHeight : Float = 175
62
+ open var alertViewWidth : Float ?
63
+
64
+ /**
65
+ Set the max alert view width
66
+ If you don't want to have a max width set this to nil.
67
+ It will take 70% of the superview width by default
68
+ Default : 450
69
+ */
70
+ open var maxAlertViewWidth : CGFloat ? = 450
62
71
63
72
fileprivate var backgroundImage : UIImageView = UIImageView ( )
64
73
fileprivate var alertView : UIView = {
@@ -164,6 +173,31 @@ open class AABlurAlertController: UIViewController {
164
173
" buttonsStackViewHeight " : ( buttonsStackView. arrangedSubviews. count > 0 ) ? 40 : 0
165
174
]
166
175
176
+ if let alertViewWidth = alertViewWidth {
177
+ self . view. addConstraints ( NSLayoutConstraint . constraints (
178
+ withVisualFormat: " H:[alertView(alertViewWidth)] " , options: [ ] ,
179
+ metrics: [ " alertViewWidth " : alertViewWidth] , views: viewsDict) )
180
+ } else {
181
+ let widthConstraints = NSLayoutConstraint ( item: alertView,
182
+ attribute: NSLayoutAttribute . width,
183
+ relatedBy: NSLayoutRelation . equal,
184
+ toItem: self . view,
185
+ attribute: NSLayoutAttribute . width,
186
+ multiplier: 0.7 , constant: 0 )
187
+ if let maxAlertViewWidth = maxAlertViewWidth {
188
+ widthConstraints. priority = 999
189
+ self . view. addConstraint ( NSLayoutConstraint (
190
+ item: alertView,
191
+ attribute: NSLayoutAttribute . width,
192
+ relatedBy: NSLayoutRelation . lessThanOrEqual,
193
+ toItem: nil ,
194
+ attribute: NSLayoutAttribute . width,
195
+ multiplier: 1 ,
196
+ constant: maxAlertViewWidth) )
197
+ }
198
+ self . view. addConstraint ( widthConstraints)
199
+ }
200
+
167
201
let alertSubtitleVconstraint = ( alertSubtitle. text != nil ) ? " spacing-[alertSubtitle]- " : " "
168
202
[ NSLayoutConstraint ( item: alertView, attribute: . centerX, relatedBy: . equal,
169
203
toItem: view, attribute: . centerX, multiplier: 1 , constant: 0 ) ,
@@ -172,8 +206,6 @@ open class AABlurAlertController: UIViewController {
172
206
] . forEach { self . view. addConstraint ( $0) }
173
207
[ NSLayoutConstraint . constraints ( withVisualFormat: " V:|-margin-[alertImage(alertImageHeight)]-spacing-[alertTitle(alertTitleHeight)]- \( alertSubtitleVconstraint) margin-[buttonsStackView(buttonsStackViewHeight)]-margin-| " ,
174
208
options: [ ] , metrics: viewMetrics, views: viewsDict) ,
175
- NSLayoutConstraint . constraints ( withVisualFormat: " H:[alertView(alertViewWidth)] " ,
176
- options: [ ] , metrics: viewMetrics, views: viewsDict) ,
177
209
NSLayoutConstraint . constraints ( withVisualFormat: " H:|-margin-[alertImage]-margin-| " ,
178
210
options: [ ] , metrics: viewMetrics, views: viewsDict) ,
179
211
NSLayoutConstraint . constraints ( withVisualFormat: " H:|-margin-[alertTitle]-margin-| " ,
0 commit comments