From 9ece3474c6800c7ee424133f2dc2d283d22eeb4a Mon Sep 17 00:00:00 2001 From: relikd Date: Mon, 29 Jun 2020 00:34:15 +0200 Subject: [PATCH] Limit CustomAlert to screen size & cut padding in half if necessary --- main/Common Classes/CustomAlert.swift | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/main/Common Classes/CustomAlert.swift b/main/Common Classes/CustomAlert.swift index 0491758..87552a6 100644 --- a/main/Common Classes/CustomAlert.swift +++ b/main/Common Classes/CustomAlert.swift @@ -58,11 +58,14 @@ class CustomAlert: UIViewController { control.addSubview(x) // sticky edges horizontally x.anchor([.leading, .trailing], to: control, margin: lr) - // chain views vertically - x.topAnchor =&= (prevView?.bottomAnchor ?? control.topAnchor) + top + chainPrevious(to: x.topAnchor, padding: top) prevView = x 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 { let lbl = QuickUI.label(t, align: .center, style: .headline) @@ -76,8 +79,7 @@ class CustomAlert: UIViewController { } appendView(customView, top: (prevView == nil) ? 0 : 16, lr: 0) appendView(buttonsBar, top: 0, lr: 25) - - buttonsBar.bottomAnchor =&= control.bottomAnchor - 15 + chainPrevious(to: control.bottomAnchor, padding: 15) h += 15 // buttonsBar has 15px padding let screen = UIScreen.main.bounds.size @@ -85,6 +87,7 @@ class CustomAlert: UIViewController { view.addSubview(control) control.anchor([.leading, .trailing, .bottom], to: view!) + control.heightAnchor =<= view.heightAnchor }