我有一个Objective-c应用程序,我正在使用autolayout . 我有一个tableview,单元格包含一个UIImageView,一个UITextView,另一个UIImageView和一个UILabel . 喜欢:
enter image description here

我想在textView下保留带有图像和标签的单元格,但是当我运行我的应用程序时,标签和图像都在textView上...

我有这个功能,根据文本的大小和字体应用UITextView的内容调整:

- (CGFloat)textViewHeightForAttributedText: (NSAttributedString*)text andWidth: (CGFloat)width {
    UITextView *calculationView = [[UITextView alloc] init];
    [calculationView setAttributedText:text];
    CGSize size = [calculationView sizeThatFits:CGSizeMake(width, FLT_MAX)];
    return size.height;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    UIFont *font = [UIFont systemFontOfSize:14.0];
    NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
    NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:brokenCars[indexPath.row] attributes:attrsDictionary];

    return [self textViewHeightForAttributedText:attrString andWidth:CGRectGetWidth(self.myTable.bounds)-31]+50;


}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
     ...
     [cell setNeedsLayout];
    [cell layoutIfNeeded];
     ...
    }

//In the UITableViewCell:

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    [self.myText sizeToFit];
    [self.myText layoutIfNeeded];
    CGSize size = [self.myText sizeThatFits:(CGSizeMake(self.myText.contentSize.width, FLT_MAX+30))];
    [self.myText setContentSize:size];
}

我添加了这个约束:要离开第一个UIImageView:

enter image description here

到UITextView:

enter image description here

要倒下UIImageView:

enter image description here

而对于UILabel:

enter image description here

我做得不好?如何移动它并始终按住UITextView?

谢谢!

编辑1:添加到更加crearly . 我想得到这个,总是textview的标签和图像dwon,但textView扩展显示所有文本:

enter image description here

我正在显示所有文本扩展,但图像和标签就像拳头图片一样在文本上 .