简体   繁体   English

更改界面方向后,UILabel的文本未居中

[英]UILabel's text not centered after changing interface orientation

There is a weird thing with label text after device is rotated, it's not centered as it should be. 旋转设备后,标签文本有些奇怪,它没有居中对齐。 Basically the container view has 11 subviews (cells). 基本上,容器视图具有11个子视图(单元格)。 The cell subviews (image and label) constrains are: 单元格子视图(图像和标签)约束为:

1) Label 1)标签

在此处输入图片说明

2) Image 2)图片

在此处输入图片说明

The cells constrains applied when they are added to the container view are: 将它们添加到容器视图时应用的单元约束为:

  • Cell 1 单元格1

    1) match top, left and right border (superview) 1)匹配顶部,左侧和右侧边框(超级视图)

    2) height equal or bigger that 15. 2)高度等于或大于15。

  • Cell 2-10 单元格2-10

    1) match left, right border (superview) 1)匹配左,右边框(预览)

    2) pin to bottom of previous cell 2)固定到上一个单元格的底部

    3) match height of previous cell 3)匹配上一个单元格的高度

  • Cell 11 单元格11

    1) match left, right, bottom border (superview) 1)匹配左,右,下边框(超级视图)

    2) pin to bottom of previous cell 2)固定到上一个单元格的底部

    3) match height of previous cell 3)匹配上一个单元格的高度

The result is the following 结果如下

  • Portrait 肖像

在此处输入图片说明

  • Landscape 景观

在此处输入图片说明

This seems a bug to me, but not sure. 对我来说,这似乎是一个错误,但不确定。 Any suggestions are welcome. 欢迎任何建议。

I would put the label inside it's own UIView object, then use the Centre Horizontally/Vertically constraints to ensure the label is centred inside the view. 我会将标签放在它自己的UIView对象中,然后使用“水平居中/垂直居中”约束来确保标签在视图内居中。

Pin the label's superview's top and bottom to the top and bottom of the coloured image, and give it an equal width constraint with the image. 将标签超级视图的顶部和底部固定到彩色图像的顶部和底部,并为其赋予与图像相等的宽度约束。 Add spacing between them and around it's edges and this should achieve what you're looking for! 在它们之间以及边缘周围增加间距,这应该可以实现您所需要的!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM