当方向发生变化时,使用 UITableView 调整 UILabel 的大小

发布于 2024-09-06 13:55:19 字数 117 浏览 5 评论 0原文

我在自定义 UITableViewCell 中有 3 个 UILabel。当设备改变其方向时,这些 UIlabel 的宽度必须改变,因为 tableView 的宽度发生了变化。我的问题是当设备旋转发生时如何调整标签大小。

I've 3 UILabel's inside a custom UITableViewCell. The width of these UIlabels must change when the device changes it's orietation because the tableView's width changes. My problem was how could I resize the label when the device rotation happens.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぺ禁宫浮华殁 2024-09-13 13:55:19

最简单的方法是将标签的 autoresizingMask 设置为适当的值。你可能会想要这样的东西:

leftLabel.autoresizingMask   = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;
centerLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
rightLabel.autoresizingMask  = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin;

The easiest way is to set the labels' autoresizingMask to appropriate values. You'll probably want something like this:

leftLabel.autoresizingMask   = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;
centerLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
rightLabel.autoresizingMask  = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文