exe*_*r21 21 iphone cocoa-touch objective-c uitableview iphone-sdk-3.0
我正在使用UITableViewCell和UITableViewCellStyleSubtitle.但是,由于我用于单元格的背景图像,我不喜欢detailTextLabel的去向.我想移动它并在单元格内调整大小,但我尝试的任何东西似乎都没有用.
CGRect currRect = cell.detailTextLabel.frame;
cell.detailTextLabel.frame = CGRectMake(currRect.origin.x + 20, currRect.origin.y, currRect.size.width - 40, currRect.size.height);
Run Code Online (Sandbox Code Playgroud)
我尝试将此代码放入tableView:cellForRowAtIndexPath和tableView:willDisplayCell:forRowAtIndexPath方法,但两者都不起作用.标签只是保持原样,大小相同.
调整标签的其他属性(textAlignment,backgroundColor,当然还有文本本身)可以正常工作.
如何让detailTextLabel移动到我需要的位置?
如果这很重要(虽然我不明白为什么它应该),这个特定的单元格也有imageView.image和backgroundImage属性设置.两个图像都正确显示.
Mar*_*ius 43
您可以尝试使用缩进和缩进级别调整标签:
cell.indentationWidth = MY_DESIRED_WIDTH;
cell.indentationLevel = 1;
Run Code Online (Sandbox Code Playgroud)
(对于未缩进的单元格)
或者对于缩进单元格,只需:
cell.indentationLevel = cell.indentationLevel + 1;
Run Code Online (Sandbox Code Playgroud)
这两个都应该移动/缩进你的标签.
And*_*iot 35
你需要一个UITableViewCell覆盖layoutSubviews 的自定义子类来完成布置其中任何子视图的脏工作.调用超级然后调整detailTextLabel.frame可能是最容易的事情.
| 归档时间: |
|
| 查看次数: |
20231 次 |
| 最近记录: |