如何根据目标 c 中的文本内容调整标签高度

RK ios

在此处输入图片说明

在此处输入图片说明

以下是不起作用的代码:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"Cell";

    MessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

    MessageObject *currentdatas = [self.objectHolderArray objectAtIndex:indexPath.row];

    cell.Name_Label.text = currentdatas.Name;
    //Here I wanted to adjust my label height according to my message received

    cell.Message_Label.text = currentdatas.MSG;
    [cell.Message_Label sizeToFit];

    NSTimeInterval timeInterval = currentdatas.time/1000;
    NSDate *date = [NSDate dateWithTimeIntervalSinceNow:timeInterval];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd-mm-yyyy"];
    NSString *dateString = [dateFormatter stringFromDate:date];
    NSLog(@"My date %@",dateString);
    cell.Time_Label.text = dateString;

    UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString:currentdatas.Profile]]];
    // Image Rectangle to circular
    cell.Image_View.image = image;
    cell.Image_View.layer.cornerRadius = cell.Image_View.frame.size.width/2;
    cell.Image_View.clipsToBounds = YES;

    return cell;
}
吉加尔

添加此方法。设置标签行数为 0。

在 tableview 中添加此代码

self.tableView.estimatedRowHeight = 80;
self.tableView.rowHeight = UITableViewAutomaticDimension;

-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {

   return UITableViewAutomaticDimension; 
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewAutomaticDimension;
}

在此处输入图片说明

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章