Limit CustomAlert to screen size & cut padding in half if necessary
This commit is contained in:
@@ -58,11 +58,14 @@ class CustomAlert<CustomView: UIView>: UIViewController {
|
|||||||
control.addSubview(x)
|
control.addSubview(x)
|
||||||
// sticky edges horizontally
|
// sticky edges horizontally
|
||||||
x.anchor([.leading, .trailing], to: control, margin: lr)
|
x.anchor([.leading, .trailing], to: control, margin: lr)
|
||||||
// chain views vertically
|
chainPrevious(to: x.topAnchor, padding: top)
|
||||||
x.topAnchor =&= (prevView?.bottomAnchor ?? control.topAnchor) + top
|
|
||||||
prevView = x
|
prevView = x
|
||||||
h += x.frame.height + top
|
h += x.frame.height + top
|
||||||
}
|
}
|
||||||
|
func chainPrevious(to anchor: NSLayoutYAxisAnchor, padding p: CGFloat) {
|
||||||
|
anchor =&= (prevView?.bottomAnchor ?? control.topAnchor) + p/2 | .defaultLow
|
||||||
|
anchor =&= (prevView?.bottomAnchor ?? control.topAnchor) + p | .defaultHigh
|
||||||
|
}
|
||||||
|
|
||||||
if let t = alertTitle {
|
if let t = alertTitle {
|
||||||
let lbl = QuickUI.label(t, align: .center, style: .headline)
|
let lbl = QuickUI.label(t, align: .center, style: .headline)
|
||||||
@@ -76,8 +79,7 @@ class CustomAlert<CustomView: UIView>: UIViewController {
|
|||||||
}
|
}
|
||||||
appendView(customView, top: (prevView == nil) ? 0 : 16, lr: 0)
|
appendView(customView, top: (prevView == nil) ? 0 : 16, lr: 0)
|
||||||
appendView(buttonsBar, top: 0, lr: 25)
|
appendView(buttonsBar, top: 0, lr: 25)
|
||||||
|
chainPrevious(to: control.bottomAnchor, padding: 15)
|
||||||
buttonsBar.bottomAnchor =&= control.bottomAnchor - 15
|
|
||||||
h += 15 // buttonsBar has 15px padding
|
h += 15 // buttonsBar has 15px padding
|
||||||
|
|
||||||
let screen = UIScreen.main.bounds.size
|
let screen = UIScreen.main.bounds.size
|
||||||
@@ -85,6 +87,7 @@ class CustomAlert<CustomView: UIView>: UIViewController {
|
|||||||
|
|
||||||
view.addSubview(control)
|
view.addSubview(control)
|
||||||
control.anchor([.leading, .trailing, .bottom], to: view!)
|
control.anchor([.leading, .trailing, .bottom], to: view!)
|
||||||
|
control.heightAnchor =<= view.heightAnchor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user