I have a UILabel
as subview of UIButton
and I am passing the value
from another view and populating in UILabel
. Now, I want that UILabel
must change its height based on the content.If text is "Hello" it must
be in 1 line but if text is " my text is too long to fit in the
label", it must change its size. I have used
[self.addressLabel sizeToFit];
But for this i need to leave empty space below UILabel. Simply what I want is that when text strength increases,size of UILabel and UIView must expand.
Using below you can get the height of the label
width - width of the label
and create a frame using the height
Use this code its very easy and updated with ios8
add this method to your appconstant file
and finally use this code for dynamic create UILabel
This is the very simplest function for getting dynamic height for labels. You can just use this function.
Here ceil is the predefind function for returns the smallest integer value. And MAXHEIGHT is maximum height for uilabel for example you can give 1000 also for future caluclations...
Here is the way that i handle this issue: