[英]Issue with UILabel center text alignment at different font sizes in Xcode Swift
This is an issue with UILabel in iOS7 and iOS8, it does not present in iOS9.
这是iOS7和iOS8中UILabel的问题,在iOS9中不存在。 This odd UILabel behaviour is experienced with different fonts, in Xcode versions 6 and 7 with Swift, using the simulator and device.
在带有Swift和模拟器的Xcode版本6和7中,使用不同的字体会遇到这种奇怪的UILabel行为。
Problem: 问题:
I have a UILabel that has a center text alignment. 我有一个具有中心文本对齐方式的UILabel。 At different font sizes, some lines of text stop being center aligned and snap to left alignment.
在不同的字体大小下,某些文本行将停止居中对齐并对齐到左对齐。 It is subtle but noticeable.
这是微妙的但值得注意的。
In the images below: 在以下图片中:
LEFT: all lines of text are centered neatly. 左:所有文本行均居中对齐。
MIDDLE: after increasing the font size, the third line from the top snaps more to the left instead of remaining centered. 中:增加字体大小后,从顶部开始的第三行向左对齐,而不是居中。 (Notice more blue space on right.)
(请注意右侧有更多蓝色空间。)
RIGHT: after increasing the font size a little more, both the second and third line from the top snap to the left instead of remaining centered. 右:稍微增加字体大小后,从顶部开始的第二行和第三行都向左对齐,而不是居中。 (Notice more blue space on right.)
(请注意右侧有更多蓝色空间。)
Questions: 问题:
UITextView
UITextView
With all due respect, it is my experience that UILabel
is plagued with bugs when it comes to multiple lines (Line count other than 1
). 出于所有应有的尊重,根据我的经验,当涉及多行(行计数不是
1
)时, UILabel
会遇到很多bug。
Starting, but not limited to sizing cells containing such labels hardly able to predict its footprint 1 . 开始但不限于确定包含此类标签的细胞的大小,几乎无法预测其足迹1 。
Use UITextView
, non editable , scrolling disabled (that is the key). 使用
UITextView
,不可编辑 , 禁用滚动(这是关键)。 You will achieve the same effects, with more control over the final appearance. 您将获得相同的效果,并且可以更好地控制最终外观。
1 See note 3 on this Stack Overflow UILabel
answer . 1请参见有关此堆栈溢出
UILabel
答案的注释3。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.