SwiftUI: Dynamic Label and Image adjust

40 Views Asked by At

We have vertically aligned multiple labels and top tight Image is align to first label.

If first label has not enough content then second label will be move up and vice versa.

image height will be dynamic.

i have also attached image as reference. enter image description here Thanks in advance.

1

There are 1 best solutions below

2
On

That works if the bell's sizes are fixed, one small and one is big.

Calculate total lenght text for every screen, totalLength = maxLenght - 4 (letters). With @State var textMaxLenght you can check text lenght for the picture If textLenght > totalLenght switch state of textMaxLenght.

example:

Maximum view disponible text lenght is 10 For calulate you take 6 (10 - 4, for bell space) Then if text 7, you compare it with 6, then you will got textMaxLenght = false, and your bell will be small in this case.