John B.
John B.

Reputation: 682

Xcode Storyboard - Where to set UITableViewCell height

I am using Xcode 7 and I am trying to set the height of a UITableViewCell in the storyboard settings to have a different cell height for different devices (eg. normal and compact x regular).

I cannot find a place for these settings. Is this only possible by doing it programmatically?

Upvotes: 3

Views: 6548

Answers (4)

user12815758
user12815758

Reputation:

You can set height from user interface and to reflect your set value you need to override table view heightForRowAt method e.g.

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 73
    }

Upvotes: 0

Anand Nimje
Anand Nimje

Reputation: 6251

Click on Table View after that click on Size Inspector

and adjust your cell row height here -

enter image description here


Add this below code in your controller class viewDidLoad

tableView.estimatedRowHeight = 100.0 // Adjust Primary table height
tableView.rowHeight = UITableViewAutomaticDimension //This line adjust cell height according to containts

Swift 4 or later

  • You need to change from UITableViewAutomaticDimension to UITableView.automaticDimension

tableView.estimatedRowHeight = 100.0 // Adjust Primary table height
tableView.rowHeight = UITableView.automaticDimension

Upvotes: 13

Brijesh shiroya
Brijesh shiroya

Reputation: 1

You can set UITableView height in this way.Try this code

 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath(NSIndexPath *)indexPath 
   {
        if UIDevice.currentDevice().userInterfaceIdiom == .Phone &&   ScreenSize.SCREEN_MAX_LENGTH < 568.0
        {
             return 97
        }
       if UIDevice.currentDevice().userInterfaceIdiom == .Phone && ScreenSize.SCREEN_MAX_LENGTH == 568.0
        {
            return 115
        }
        if UIDevice.currentDevice().userInterfaceIdiom == .Phone && ScreenSize.SCREEN_MAX_LENGTH == 667.0
        {
            return 135
        }
        if UIDevice.currentDevice().userInterfaceIdiom == .Phone && ScreenSize.SCREEN_MAX_LENGTH == 736.0
        {
            return 150
        }
   return 90
}

Upvotes: 0

Said Sikira
Said Sikira

Reputation: 4543

Go to the storyboard, find you table view and select the cell. You will notice a white square at the bottom middle of the cell. You can drag it to change the cell height.

Change cell height

Upvotes: 4

Related Questions