我试图让我的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