Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change height of UITableView cell in Swift?

I am trying to show a comment on an app like in the following pictures. I'm using Xcode 9.4.1.

app view

I use the following code to hide the label:

if commentManager == nil {
    cell.managerReplyLabel.isHidden = true
    cell.ratingManagerLabel.isHidden = true
}

But it looks still like it has a space on it which I hidden two labels.

I try to use cell.ratingManagerLabel.font.withSize(0) or cell.ratingManagerLabel.frame.size.height = 0 to change the label hight, but it doesn't work.

How to reduce the space?

Update:

I use storyboard to set the screen and auto-layout.

autolayout

import UIKit
import Cosmos

class RatingTableViewCell: UITableViewCell {

    @IBOutlet weak var userNameLabel: UILabel!
    @IBOutlet weak var ratingStar: CosmosView!
    @IBOutlet weak var ratingUserLabel: UILabel!
    @IBOutlet weak var ratingManagerLabel: UILabel!

    @IBOutlet weak var managerReplyLabel: UILabel!

}
like image 214
Peggy Avatar asked Dec 06 '22 11:12

Peggy


1 Answers

Use the delegate method in your UITableView Class.

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
{
    return 200 //or whatever you need
}
like image 69
Daniel Espina Avatar answered Dec 08 '22 01:12

Daniel Espina