Posts

Showing posts from January, 2017

UILabel dynamic height with Autolayout

Image
Adding a UILabel to UIScrollView and with a couple of lines of code you would be able to achieve the dynamic height. But, there is one more way and thats without writing a single line of code. So, lets get started on it. Approach 1: Mistakes that we would make is explained below. (UILabel and UIScrollView) Add a UIScrollView , set top, left, bottom, right margin set to 0 against superview as per your requirement. Add the UILabel and we do the same for UILabel (top,left,bottom,right margin set to 0 with respect to SuperView, which is UIScrollView ) With this approach scrollview would not get idea on the scroll limits. It will set the content size, where it would scroll horizontally. You can still go with this approach. Explained in conclusion. Approach 2: Now, lets go with the correct way to Code .  It includes the following hierarchy UIView -> UIScrollView -> UILabel. Step 1  : Add the UIView , set the margin according. Here I am using