2013-07-23 31 views
0

我需要在我的UITableView中設置三行detailTextLabelUITableView的textLabel.text位置不在iOS中心

所以我設置下面的代碼在我CellForRowAtIndexPath

cell.detailTextLabel.numberOfLines = 3; 
cell.detailTextLabel.textAlignment = NSTextAlignmentCenter; 

之後我設置的是,我的cell.TextLabel.text位置正在發生的事情就像下面照片。

enter image description here

我想這cell.textLabel.文本中心,而不是在頂部。

我該怎麼做?

回答

1

TextLabel目前尚未具有One Line的高度。

子類UITableViewCell並重置TextLabel的Frame。

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

所以它是一樣的detailTextLabel的,例如:

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

這應使兩者的高度和垂直居中你的字符串,您可以更改標籤的框架。