iOS:UILabel &表格单元格中的 UIButton
我试图在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终选择了子类化
UITableViewCell
&覆盖layoutSubViews
。谢谢马克!I finally went with subclassing
UITableViewCell
& overridinglayoutSubViews
. Thanks Mark!