UILabel and UITextView calculate baselines in a different way

Originator:avedesk
Number:rdar://28913460 Date Originated:24-Oct-2016 12:01 PM
Status:Open Resolved:
Product:iOS SDK Product Version:
Classification:Other Bug Reproducible:Always
 
Summary:
Trying to align a UILabel and a UITextView by baseline is no funny matter. Turns out, UILabel clamps its baseline to pixel values using round (UIViewRoundToScale), while UITextView uses ceil, but this doesn't seem to be documented anywhere. One would expect the calculation to be done in a consistent way.

Steps to Reproduce:
1. Try to align the text in a UILabel and UITextView on baselines, with font size = 17.0
2. Have pixel differences between the two, depending on font-size and the line number in UITextView one is trying to align to
3. Dive into disassembly of CoreText, CoreGraphics, UIKit. (Apple engineers can skip this step and look at the actual code directly, likely)
4. Take hours to figure out why a UILabel is sometimes misaligned with respects to a UITextView baseline

Expected Results:
1. UILabel and UITextView calculate their baselines in the same way

Actual Results:
- UILabel calculates its baseline position by taking the actual fractional baseline and rounding it to pixel values. A Baseline of 16.12 comes out as 16
- UITextView (CoreText) calculates its baseline position by taking the actual fractional baseline and ceil()-ing it to pixel values. A baseline of 16.12 comes out as 16.5 on 2x devices.
- This results in pixel differences sometimes, depending on font-size and where the actual line starts
- Developer goes crazy and knows more about the inner workings of text rendering on IOS than they want

Regression:

Notes:

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!