sniurkst sniurkst - 1 year ago 107
iOS Question

How to lose margin/padding in UITextView?

I have a

in my iOS Application, which displays a large amount of text. I am then paging this text by using the offset margin parameter of the
. My problem is that the padding of the
is confusing my calculations as it seems to be different depending on the font size and typeface that I use.

Therefore, I pose the question: Is it possible to remove the padding surrounding the content of the
? Look forward to hearing your responses!


The QA on this page dates from 2009...

The problem is finally solved (2016+)

Answer Source

I ran into the exact same problem, in the end I had to wind up using

nameField.contentInset = UIEdgeInsetsMake(-4,-8,0,0);

where nameField is a UITextView. The font I happened to be using was Helvetica 16 point. Its only a custom solution for the particular field size I was drawing. This makes the left offset flush with the left side, and the top offset where I want it for the box its draw in.

In addition, this only seems to apply to UITextViews where you are using the default aligment, ie.

nameField.textAlignment = NSTextAlignmentLeft;

Align to the right for example and the UIEdgeInsetsMake seems to have no impact on the right edge at all.

At very least, using the .contentInset property allows you to place your fields with the "correct" positions, and accommodate the deviations without offsetting your UITextViews.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download