struggling with formatting dynamic row height in UITableView

后端 未结 3 1251
清歌不尽
清歌不尽 2021-02-06 18:30

I am trying to resize the height of my row in UITableView based on the text length. I have the following code:

- (CGFloat)tableView:(UITableView *)tableView heig         


        
3条回答
  •  猫巷女王i
    2021-02-06 19:13

    I think the built in imageView will ignore your attempts to resize it. Subclass UITableViewCell and add your own custom UIImageView to it. Then you can control all aspects of your image view.

    -- wisenomad's solution will work without having to add your own custom image view and labels. --

    You will also have to change the frame of the textLabel. Here is an example.

    - (void)layoutSubviews {
            [super layoutSubviews];
            float sideLength = self.frame.size.height;
            self.imageView.frame = CGRectMake(0.0, 0.0, sideLength, sideLength);
            CGRect textLabelFrame = self.textLabel.frame;
            self.textLabel.frame = CGRectMake(44.0, textLabelFrame.origin.y, textLabelFrame.size.width - 44.0 + textLabelFrame.origin.x, textLabelFrame.size.height);
        }
    

提交回复
热议问题