Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plain text being cut off at bottom in iOS, how to fix in xCode?

I noticed in my iOS app, for text that are using a system font with size 20 pt or more, the bottom of text is being cut off.

For example, the bottom portion of the letters y, g, p, and g are being cut off.

How do I fix this in Xcode?

like image 895
user3108698 Avatar asked Nov 06 '14 00:11

user3108698


2 Answers

If your using something like a UILabel it means you will need to increase the vertical height of that element.. Either in code or in interface builder.

If you are doing it in code you can get the label to resize itself to fit the contents by calling sizeToFit..

[myLabel sizeToFit];

Alternatively you could measure the size to the string by using sizeWithAttributes: then change the size of the label accordingly.

like image 127
Ron Avatar answered Nov 11 '22 07:11

Ron


Updating this one for Swift 3.x in a UITableViewController.

In cellForRowAtIndexPath after the problematic label is set, but before the cell is returned from the method, add a line something like this:

cell.myLabelWhoseCharactersLikegyqGetCutOff.sizeToFit()
like image 31
Adrian Avatar answered Nov 11 '22 06:11

Adrian