iOS:UILabel &表格单元格中的 UIButton

发布于 2024-11-14 05:57:00 字数 433 浏览 3 评论 0原文

我试图在 UITableViewCell 中并排显示标签和按钮。该按钮位于右端和右端。标签位于左端。标签可以承载很长的文本,如果文本超出范围(我不想减小字体大小等),则应该被截断。不用说,我希望这对两个方向都适用。

如果我使用 UITableViewCellStyleDefault (不添加按钮)&为默认标签设置长文本,我观察到当方向改变时标签会完美地自动调整大小。很可能是因为它的 autoresizingMask 设置为 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin。现在,在我看来,如果我可以配置默认使用的右边距的值(以适应按钮),我可以插入按钮,并使标签正确截断。我本质上希望它在我指定的范围内自动调整大小。有没有办法可以实现这一点?

我不喜欢听每个方向的变化并设置标签框架的边界。还有其他可行的方案吗?

I am trying to display a Label and a button side-by-side in a UITableViewCell. The button sits at the right end & the Label sits at the left end. The label can host a long text and should get truncated if the text would flow out of bounds (I do not want to reduce the font size, etc.). Needless to say, I want this to work for both the orientations.

If I use UITableViewCellStyleDefault (without adding a button) & set a long text for the default label, I observe that the label auto-resizes perfectly when the orientation changes. Most probably because its autoresizingMask is set to UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin. Now, the way I see it, I could insert my button, and make the label truncate properly, if I could configure the value of the right margin that is being used by default (to accommodate the button). I essentially want it to auto-resize within the bounds that I specify. Is there a way this can be accomplished?

I would not prefer listening to each orientation change and setting the bounds of the label's frame. Any other feasible solution?

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

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

发布评论

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

评论(1

苍风燃霜 2024-11-21 05:57:00

我最终选择了子类化 UITableViewCell &覆盖layoutSubViews。谢谢马克!

I finally went with subclassing UITableViewCell & overriding layoutSubViews. Thanks Mark!

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