我試圖讓我的UITableViewCell.textLabel
屬性垂直和水平自動適應文本。UITableViewCell適合整個框架的textLabel
現在我的tableView
不可滾動,因此cell
框架不是動態的。我需要textLabel
屬性來自動換行並調整大小爲一組行。將numberOfLines
設置爲0不起作用,因爲它被切斷,因爲我的cell
高度小於textLabel
最終高度。使用numberOfLines
的任意數字會切斷文本。
如何調整我的textLabel
以適合cell
的frame
?
下面
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell* cell = (UITableViewCell*)[tableView @"mycell"];
cell.textLabel.text = @"LOTS OF TEXT";
cell.textLabel.textAlignment = NSTextAlignmentCenter;
[cell.textLabel textRectForBounds:cell.bounds limitedToNumberOfLines:0];
cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
cell.textLabel.numberOfLines = 0;
cell.textLabel.adjustsFontSizeToFitWidth = YES;
cell.textLabel.minimumScaleFactor = .5;
}
你的意思是你想調整基於textLable內容的單元格? – 2015-02-09 13:05:48
@sanginadhammurali不,細胞高度是靜態的。我想調整基於靜態高度 – DaynaJuliana 2015-02-09 19:17:57
的'textLabel'的大小,嘗試在nib文件中給出可文本框架的x和y位置(0,0),並且如果文本行超過兩個並且甚至在給出NSLineBreakByWordWrapping之後,則不是然後工作,然後增加可操作的文本。 – 2015-02-10 04:16:40