gpt4 book ai didi

ios - UIlabel 在文本前显示额外的空间

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:07:42 25 4
gpt4 key购买 nike

我在我的应用中使用了 UILabel。它在纵向模式下工作正常。但是当我以横向模式打开我的应用程序时,它会在 UIlabel 的中心显示内容。我试过 sizeToFit 但它不起作用。一旦我增加 uilabel 的宽度间距就开始到达 uilabel。

我的代码:

self.contentLabel.text = labeltext;
[self.contentLabel setNumberOfLines:0];
[self.contentLabel sizeToFit];

最佳答案

我怀疑您的 UILabel 本身而不是其中的文本在旋转时实际上没有正确对齐。确保标签与 View 顶部保持对齐。尝试:

self.contentLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight;

self.contentLabel.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

编辑:另一个想法。

如果启用了自动布局并且您在 viewDidLoad 中调用了 sizeToFit,则可能在自动布局布置 subview 后 View 正在调整大小。尝试将您的代码放在 viewDidLayoutSubviews 中。

关于ios - UIlabel 在文本前显示额外的空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21847010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com