Actually, I just needed to read Apple's NSAttributedText documentation.
In my case, I have to replace the last two lines of code with
CGRect rectSize = [theText boundingRectWithSize:CGSizeMake(labelWidth, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin context:NULL]; return rectSize.size.height+VERTICAL_CELL_PADDING;
FOLLOW UP iOS 7
I am trying to make this work in iOS7 with attributed text.
Apple documentation says
In iOS 7 and later, this method returns fractional sizes (in the size of the components returned by CGRect); use the return size by the size of the views you should use to increase its value to the nearest higher integer using the ceil function.
Which way obviously doesn't work for me! For me, the solution was to add +1 to the ceiling height. This is probably Apple's mistake, but now everything works for me like in iOS6.
CGRect rectSize = [theAttributedText boundingRectWithSize:CGSizeMake(labelWidth, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin context:NULL]; return ceil(rectSize.size.height) + 1 + VERTICAL_CELL_PADDING;
source share