如何更改UITableViewCellStyleValue2单元格上的标签大小? (UITableView iPhone) [英] How to change the size of the labels on a UITableViewCellStyleValue2 cell? (UITableView iPhone)
问题描述
我在我的应用程序中的UITableView中使用了UITableViewCellStyleValue2单元格,我希望左列(蓝色文本 - self.textField)比默认值窄得多。我在创建单元格之后尝试设置self.textField.bounds,但这似乎不起作用 - 在调试器中查看它的边界尚未设置。
I'm using a UITableViewCellStyleValue2 cell in my UITableView in my app and I want the left column (the blue text - self.textField) to be much narrower than the default. I've tried setting the self.textField.bounds after creating the cell but this doesn't seem to work - looking in the debugger it appears the bounds haven't been set.
我可以用这种方式编辑默认的单元格类型,还是应该创建自己的UITableViewCell子类?
Can I edit the default cell type in this way, or should I just make my own subclass of UITableViewCell?
谢谢。
推荐答案
你可以继承 UITableViewCell
并仍然使用 UITableViewCellStyleValue2
。然后,您可以覆盖layoutSubviews方法以更改标签的大小:
You can subclass UITableViewCell
and still use UITableViewCellStyleValue2
. You can then overwrite the layoutSubviews method to change the size of the labels:
- (void) layoutSubviews {
[super layoutSubviews]; // layouts the cell as UITableViewCellStyleValue2 would normally look like
// change frame of one or more labels
self.textLabel.frame = CGRectMake(...);
self.detailTextLabel.frame = CGRectMake(...);
}
这篇关于如何更改UITableViewCellStyleValue2单元格上的标签大小? (UITableView iPhone)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!