iOS 动态行宽
有没有办法让行上的文本占据整个空间,具体取决于模式(横向或纵向),而无需在某个索引处的每个字符后插入新行?
这是它在纵向模式下的样子;
横向;
正如您所看到的,在横向模式下,文本的格式不正确。
Is there a way I could make the text on a row occupy the whole space , depending on the mode (landscape or portrait ) without inserting a new line after each character at a certain index ?
This is how it looks on portrait mode;
And in landscape;
As you can see, in landscape mode, the text is not well formatted.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有
UITableViewCell
子类,则需要重写子类中的layoutSubviews
方法。如果您要在
tableView:cellForRowAtIndexPath:
方法中向表格单元格添加子视图,请在文本标签上使用label.autoresizingMask = UIViewAutoresizingFlexibleWidth
。如果您要在 Interface Builder 中布局单元格,请确保已在文本标签上设置自动调整大小锚点,以便在其父视图展开时文本标签也随之展开。您将在 Xcode 4.2 的“实用工具”窗格的第五个选项卡(带有标尺图像的选项卡)中找到自动调整大小锚点。
If you have a
UITableViewCell
subclass, you need to override thelayoutSubviews
method in your subclass.If you are adding subviews to your table cell in the
tableView:cellForRowAtIndexPath:
method, uselabel.autoresizingMask = UIViewAutoresizingFlexibleWidth
on your text label.If you are laying out the cell in Interface Builder, make sure you have set the autosizing anchors on the text label so that it expands when its superview expands. You will find the autosizing anchors in the fifth tab (the one with the image of a ruler) of the Utilities pane in Xcode 4.2.