UITableView的textLabel.text位置不是iOS的中心

时间:2013-07-23 07:35:43

标签: ios cocoa-touch uitableview

我需要在detailTextLabel中设置UITableView的三行。

所以我在CellForRowAtIndexPath

中设置了以下代码
cell.detailTextLabel.numberOfLines = 3;
cell.detailTextLabel.textAlignment = NSTextAlignmentCenter;

在我设置之后,我的cell.TextLabel.text位置正如下图所示。

enter image description here

我希望cell.textLabel.文本位于中心,而不是顶部。

我该怎么做?

2 个答案:

答案 0 :(得分:2)

您可以更改标签的框架,使其与detailTextLabel相同,例如:

CGRect tempFrame = [[cell textLabel] frame];
tempFrame.size.height = [[cell detailTextLabel] frame].size.height;
[[cell textLabel] setFrame:tempFrame]; 

这应该均衡它们的高度并垂直居中你的字符串。

答案 1 :(得分:1)

TextLabel目前的高度为One Line。

SubClass一个UITableViewCell并重置TextLabel的框架。

@implementation UINewTableViewCell
- (void) layoutSubviews {
     [super layoutSubviews];
     CGFloat aHeight = 100.0; // Set height according your requirement.
     self.textLabel.frame = CGRectMake(0, 0, 320, aHeight);
}
@end
相关问题