I am using UILabel and UITextView and they render text differently. It seems that UITextView offsets text by 4.
Below is an example where at the top is UILabel and bellow is UITextView. They both use same font. Two examples are here, one with the custom OpenSans font and one with the system's HelveticaNeue font.
UILabel is being resized after setting the text by using sizeThatFits:
label.text = text;
CGFloat width = 320 - 2 * 16; // both label and textView end up with 288 width
CGSize size = [label sizeThatFits:CGSizeMake(width, CGFLOAT_MAX)];
CGRect frame = CGRectMake(16, 0, width, size.height);
label.frame = frame;
UITextView.textContainerInset is set to (0,0,0,0).
Any help? Here are the screenshots:
1.1 HelveticaNeue: textView offset -4 (label on top)
1.2 HelveticaNeue: aligned (label on top)
2.1 OpenSans: textView offset -4 (label on top)
2.2 OpenSans: aligned (label on top)
This works for me and eliminates the inner padding:
textView.textContainer.lineFragmentPadding = 0;
textView.textContainerInset = UIEdgeInsetsZero;
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