我创建了一个带有 NIB 文件的 UITableViewCell。其中有 1 个标签将包含一条推文。所以它需要是一个动态的高度。还有一个 timeAgo 标签必须放在 tweet 标签下面。
我正在尝试框架大小的东西,但我无法获得完美的解决方案。我在 drawrect 方法的 UITableViewCell 文件中执行此操作。
self.tweet.lineBreakMode = UILineBreakModeWordWrap;
self.tweet.numberOfLines = 0;
self.tweet.font = [UIFont fontWithName:@"Arial" size:13.0f];
[self.tweet sizeToFit];
CGFloat tweetHeight = self.tweet.frame.size.height;
self.timeAgo.lineBreakMode = UILineBreakModeWordWrap;
self.timeAgo.numberOfLines = 0;
self.timeAgo.font = [UIFont fontWithName:@"Arial" size:11.0f];
[self.timeAgo sizeToFit];
CGFloat timeAgoHeight = self.timeAgo.frame.size.height;
self.timeAgo.frame = CGRectMake(88, tweetHeight, 100, timeAgoHeight + 10.0f);
我还尝试了在教程中找到的 stringhelper。
这:
- (CGFloat)RAD_textHeightForSystemFontOfSize:(CGFloat)size {
我的 HeightForRow 方法也已经不同,因为我使用了不同的单元格样式。目前我为每个单元格样式返回一个硬值,但这也需要更改为单元格高度。