From 5ab65daca100473b430c899be4e55113ce6beafd Mon Sep 17 00:00:00 2001 From: Michel Fortin Date: Sat, 24 Feb 2024 13:32:23 -0500 Subject: [PATCH] Adding optional labelWidthRatio so the width ratio constrain between label and content is optional. --- Sources/MFXUI/Forms/Form.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Sources/MFXUI/Forms/Form.swift b/Sources/MFXUI/Forms/Form.swift index 49008b2..c5a1eeb 100644 --- a/Sources/MFXUI/Forms/Form.swift +++ b/Sources/MFXUI/Forms/Form.swift @@ -34,7 +34,7 @@ open class MFFormView: UXView { } } - public init(layout: Layout = .default, @UXViewBuilder _ subviews: () -> [UXView]) { + public init(layout: Layout = .default, labelWidthRatio: CGFloat? = nil, @UXViewBuilder _ subviews: () -> [UXView]) { self.stack = UXStackView(axis: .vertical, spacing: MFFormView.rowSpacing, subviews) let labelGuide = UXLayoutGuide() @@ -69,9 +69,11 @@ open class MFFormView: UXView { contentGuide.trailingAnchor.constraint(equalTo: trailingAnchor), ]) - labelGuide.widthAnchor.constraint(equalTo: contentGuide.widthAnchor, multiplier: 0.5) - .withPriority(.defaultHigh) - .isActive = true + if let labelWidthRatio { + labelGuide.widthAnchor.constraint(equalTo: contentGuide.widthAnchor, multiplier: labelWidthRatio) + .withPriority(.defaultHigh) + .isActive = true + } labelGuide.widthAnchor.constraint(lessThanOrEqualTo: contentGuide.widthAnchor, multiplier: 1) .withPriority(.required) .isActive = true