Lots of people question, what is the best way to make dynamic view size depending on the text height. From iOS 9 we have an approach called Adaptive Layout (available when working with AutoLayout and SizeClasses).
- The first thing that I will do is create the labels with different frames and different text sizes and also set the leading and top constraints for both.
- Next, I will continue with setting the width constraint to equal the super view and then change its multiplier. To explain more here, I will set the multiplier to 0.877 because the view takes 87.7% of its super view. That means in whatever screen size you run the app, that component will take 87.7% of the width of the screen (in our case).
3. Now the main thing is NOT to set the Height constraint. You can see a yellow warning if you aren’t using SizeClasses but ignore that. This tells the interface builder to adapt on its own.
Here is the final result: