Question

The bottom line is that I'm trying to reproduce the UI that iMessage has. For the Label: The special padding of that type of text made me create a custom UILabel. Here's the code under drawTextInRect:

[super drawTextInRect:UIEdgeInsetsInsetRect(rect, UIEdgeInsetsMake(0, 15.0, 5.0, 15.0))];

No mystery for now.

The problem comes when my cell (that contain that label has to calculate height). The Label gets a rounding effect on the label like so:

cell.message.layer.cornerRadius = 18;
[cell.message sizeToFit];

Apparently I can't get the proper height and width of that label. I'm using sizeToFit and then I mesure the possible sizes with "sizeWithFont:" (deprecated in iOS 7) and "boundingRectWithSize:". The only way the text can show properly is adding manually an undetermined amount of size to height and width once the calculations are made.

The best I can get then is a screen that may look good but still has some problems and not draws properly the texts.

The link has a screen of some of the screens not showing properly.

Was it helpful?

Solution

The only answer I've been able to see looking at code from other people is that they at some point make their own calculations based on letter size.

Anyone with this problem check : https://github.com/jessesquires/MessagesTableViewController

It was the only source I could find, at the end for some cases the boundingRectWithSize is not good enough.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top