This repository was archived by the owner on Feb 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 264
Proportionally resizing subviews of vertical StackLayout with max height #185
Copy link
Copy link
Open
Description
I'm trying to setup a layout consisting of two labels placed vertically in StackLayout that has defined height. Labels should adjust it's font size according to available space. However, layouting engine scales only bottom label, preserving size of the top one. Here is demo code taken form an example app, changed to cover this case:
open class MiniProfileLayout: InsetLayout<View> {
public init(name: String, headline: String) {
let nameLayout = LabelLayout(
text: name,
font: UIFont.systemFont(ofSize: 40),
config: { label in
label.adjustsFontSizeToFitWidth = true
label.minimumScaleFactor = 0.5
})
let headlineLayout = LabelLayout(
text: headline,
font: UIFont.systemFont(ofSize: 40),
config: { label in
label.adjustsFontSizeToFitWidth = true
label.minimumScaleFactor = 0.5
}
)
super.init(
insets: UIEdgeInsets.zero,
sublayout: StackLayout(axis: .vertical, spacing: 0, sublayouts: [nameLayout, headlineLayout]),
config: { view in
view.backgroundColor = UIColor.white
}
)
}
}
Fonts are set to 40 points, and entire view has height of 80 - they can't feet intentionally and they need to resize. And instantiating the view:
let profile = MiniProfileLayout(
name: "FooBar",
headline: "BarFoo"
)
profile.arrangement(width: view.bounds.width, height: 80).makeViews(in: view)
Metadata
Metadata
Assignees
Labels
No labels
