小编Rol*_*ers的帖子

UITableViewCell动态高度:/

嘻嘻,

我创建了一个带有NIB文件的UITableViewCell.其中有一个标签,其中包含一条推文.所以它需要是一个动态的高度.还有一个timeAgo标签必须适合推文标签下方.

我正在尝试使用frame en sizes的东西,但我无法获得完美的解决方案..我在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);
Run Code Online (Sandbox Code Playgroud)

我也尝试过在教程中找到的字符串.

的:

- (CGFloat)RAD_textHeightForSystemFontOfSize:(CGFloat)size {
Run Code Online (Sandbox Code Playgroud)

我的HeightForRow方法也已经不同了,因为我使用不同的单元格样式.目前,我为每个单元格样式返回一个硬值,但也需要更改为单元格高度.

希望你们能指出我的方向.

谢谢,

  • 罗尔夫

iphone dynamic row-height uitableview

2
推荐指数
1
解决办法
7471
查看次数

标签 统计

dynamic ×1

iphone ×1

row-height ×1

uitableview ×1