Skip to content
This repository was archived by the owner on Feb 17, 2021. It is now read-only.
This repository was archived by the owner on Feb 17, 2021. It is now read-only.

Proportionally resizing subviews of vertical StackLayout with max height #185

@bparol

Description

@bparol

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)

And result:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions