I have a UIView displaying an NSAttributedString. It's set up to resize to fit its contents.
I'd like to create some padding between the text and the view, however it's not quite working. If I do this...
view.textContainerInset = UIEdgeInsetsMake(0, 15, 0, 15);
... then the left and right edges are padded, and the top and bottom have no space. This is correct. I then add in a top inset:
view.textContainerInset = UIEdgeInsetsMake(15, 15, 0, 15);
Now the top has 15 points padding, but suddenly the bottom is padded a little too (by about 10 points).
If I then add 15 points bottom padding the bottom becomes too large and the spacing isn't the same all the way round. Instead, I have to fudge it:
view.textContainerInset = UIEdgeInsetsMake(15, 15, 5, 15);
Is this an iOS 7 bug or am I misunderstanding something? I'm loathed to fudge the bottom value without understanding what's going on.
I'm not sure what gives but I'm having the same problem, seemingly a bug on Apple's part. I'm testing on iOS7.1.
In my particular case, I'm trying to add some inset to the top and the bottom, eg.
view.textContainerInset=UIEdgeInsetsMake(100, 0, 100, 0);
As the original question states, the bottom inset of 100 is seemingly ignored. What I stumbled upon is that I can do this:
view.textContainerInset=UIEdgeInsetsMake(100, 1, 100, 0);
This gives me the expected bottom inset. I can live with the (alleged) 1 point inset on the left and so I'm going to use this as a workaround that should (theoretically) work under the current version of iOS and not completely break once they fix the bug. I'll also of course submit a bug report.
Still present in iOS 8.4 (Simulator).
If Inset left
and right
are 0, the bottom is not respected.
It is respected if any property of left or right is not 0:
_title.textContainerInset = UIEdgeInsetsMake( dy, 0, dy, 0.001);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With