2011-10-16 18 views
2

我試圖讓UITable視圖的節標題中的文本換行和/或滾動。如何在UITableView節標題中進行文本換行或滾動?

我已經試過這樣:

// support line break mode for multiline 
headerLabel.lineBreakMode = UILineBreakModeWordWrap; 

// 0 means any number of lines - necessary for multiline 
headerLabel.numberOfLines = 0; 

// fit the text 
[headerLabel sizeToFit]; 

,但沒有運氣。

對此提出建議?

回答

0

就標籤而言,這就是你需要做的所有工作。一個問題/建議,你正在做這個到tableView的– tableView:viewForHeaderInSection:方法中的標籤,對吧?

1

viewForHeaderInSection試試這個示例:

UIView* customView = [[UIView alloc] init]; 
UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero]; 
headerLabel.backgroundColor = [UIColor clearColor]; 
headerLabel.opaque = YES; 
headerLabel.textColor = [UIColor whiteColor]; 

headerLabel.highlightedTextColor = [UIColor whiteColor]; 

headerLabel.shadowColor = [UIColor colorWithRed:0.0f/255.0f green:0.0f/255.0f blue:0.0f/255.0f alpha:0.25f]; 
headerLabel.shadowOffset = CGSizeMake(0.0f, -1.0f); 

headerLabel.font = [UIFont boldSystemFontOfSize:16]; 
headerLabel.frame = CGRectMake(10.0, 0.0, 232.0,40.0); 

headerLabel.numberOfLines=2; 
headerLabel.text=[self.keys objectAtIndex:section]; 

[customView setBackgroundColor:[UIColor colorWithRed:0.64f green:0.68f blue:0.72f alpha:1.0f]]; 
[customView addSubview:headerLabel]; 

return customView; 
2

確保您設置頭的使用

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

高度
相關問題