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

Proportionally resizing subviews of vertical StackLayout with max height #185

Open
bparol opened this issue Feb 13, 2018 · 0 comments
Open

Comments

@bparol
Copy link

bparol commented Feb 13, 2018

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

@bparol bparol closed this as completed Mar 12, 2018
@bparol bparol reopened this Mar 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant