UITableViewCellの高さを可変にする

iPhone

“- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath”に以下を書き込めばよし!
UILabelを追加せずに、uitableviewcellの中のlabelの高さを変化させます

        float cellHeight;
        
        UITableViewCell *cell = [self tableView:tableView
                          cellForRowAtIndexPath:indexPath];
        CGSize size = [cell.textLabel.text sizeWithFont:cell.textLabel.font
                                      constrainedToSize:tableView.frame.size
                                          lineBreakMode:UILineBreakModeWordWrap];
        
        cellHeight = size.height;
        return cellHeight + 15;
       

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です