I have a design that I want to achieve in SwiftUI, and there are three examples shown below.
It's a VStack that contains an Image, and two Text views.
- It should show no more than three lines of text, ie the container view should not grow in height if both Text views would have enough text for two rows
- It should not shrink in height when there is only one line of text for each text view.
- It should support dynamic font sizes


There is a trick to accomplish this. I'm assuming the title and subTitle will have a maximum of three lines. The idea is to create a Text with a placeholder that has up to three lines. Then add the overlay of your two title and subTitle
Views to this placeholder.This is the output when
titleFont = .title3andsubTitleFont = .subheadline:Updated: As @Benzy pointed out in his comment, the placeHolder string could be sufficient with title, subTitle, and extra new line (\n). However, I decided to keep it as a dummy text cause there are cases when either
titleorsubTitleare empty, even both of them.Updated 2: Removed placeholder stuff since @miltenkot gave idea on
reservesSpace.