views:

2569

answers:

2

Hello,

I have UITextView view in my Iphone application which displays large text and I am paging that text with offset margin, but the problem is, that it has some kind of margin or padding and it messes up my calculations (it seems to be diffferent depending on font style).

Is it possible to get rid of that unnessecary space around UITextViews contents?

+12  A: 

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 = UITextAlignmentLeft;

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.

Michael
This partially helps me in my situation... the padding also seems to be on the right side, however using UIEdgeInsetsMake(-4,-8,0,-8) seems to have no effects. This is creating a lot of problems for me when I try to compute the height of my content with sizeWithFont. If I put a UILabel side by side with my UITextView, it clearly doesn't have the same size (more text fits per line in the UILabel). Any other ideas?
Mike A
A: 

Thanks a ton for sharing your solution. It worked for me on the first go.

tanu