summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2021-10-11 10:42:55 +0200
committerAndrej Mihajlov <and@mullvad.net>2021-11-03 13:30:51 +0100
commit6a5c6c864947306669abdada657a629ade36ee7d (patch)
tree83449b41d490c6b529679d3cc7070ca78713e2ba
parent7048540407083c7e557bac2419fbbb6d3433f868 (diff)
downloadmullvadvpn-6a5c6c864947306669abdada657a629ade36ee7d.tar.xz
mullvadvpn-6a5c6c864947306669abdada657a629ade36ee7d.zip
SettingsCell: layout edit and reorder control relative to layout margins on iOS 12
-rw-r--r--ios/MullvadVPN/SettingsCell.swift44
1 files changed, 44 insertions, 0 deletions
diff --git a/ios/MullvadVPN/SettingsCell.swift b/ios/MullvadVPN/SettingsCell.swift
index fcda176f86..8bac28f783 100644
--- a/ios/MullvadVPN/SettingsCell.swift
+++ b/ios/MullvadVPN/SettingsCell.swift
@@ -70,6 +70,16 @@ class SettingsCell: BasicTableViewCell {
}
}
+ override func layoutSubviews() {
+ super.layoutSubviews()
+
+ if #available(iOS 13, *) {
+ // no-op
+ } else {
+ layoutSubviewsiOS12()
+ }
+ }
+
private func setLayoutMargins() {
// Set layout margins for standard acceessories added into the cell (reorder control, etc..)
layoutMargins = UIMetrics.settingsCellLayoutMargins
@@ -97,4 +107,38 @@ class SettingsCell: BasicTableViewCell {
}
}
}
+
+ /// On iOS 12, standard edit and reorder controls do not respect layout margins.
+ /// This method does layout adjustments to fix that.
+ private func layoutSubviewsiOS12() {
+ guard isEditing || showsReorderControl else { return }
+
+ var leftOffset: CGFloat = 0
+ var rightOffset: CGFloat = 0
+
+ for subview in subviews {
+ // Detect the edit control and move it, so that the nested image view is aligned along the left edge of the
+ // layout margins.
+ if subview.description.starts(with: "<UITableViewCellEditControl"), let imageView = subview.subviews.first {
+ let imageOffset = imageView.frame.minX
+ var pos = subview.frame.origin
+ pos.x = layoutMargins.left - imageOffset
+ subview.frame.origin = pos
+ leftOffset = pos.x
+ }
+
+ // Detect the reorder control and move it, so that its right edge is aligned along the right edge of the
+ // layout margins.
+ if subview.description.starts(with: "<UITableViewCellReorderControl") {
+ var pos = subview.frame.origin
+ pos.x -= layoutMargins.right
+ subview.frame.origin = pos
+ rightOffset = layoutMargins.right
+ }
+ }
+
+ // Adjust the content view to account for the adjustments to the edit and reorder controls.
+ let contentInset = UIEdgeInsets(top: 0, left: leftOffset, bottom: 0, right: rightOffset)
+ contentView.frame = contentView.frame.inset(by: contentInset)
+ }
}