UITextView offsets text differently than UILabel

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)
HelveticaNeue:偏移-4

1.2 HelveticaNeue: aligned (label on top)
HelveticaNeue  - 对齐

2.1 OpenSans: textView offset -4 (label on top)
OpenSans  - 偏移-4

2.2 OpenSans: aligned (label on top)
OpenSans  - 对齐


这适用于我,并消除了内部填充:

textView.textContainer.lineFragmentPadding = 0;
textView.textContainerInset = UIEdgeInsetsZero;
链接地址: http://www.djcxy.com/p/28276.html

上一篇: 如何使用自动布局设置tableHeaderView(UITableView)的高度?

下一篇: UITextView补偿文本与UILabel不同