Reputation: 682
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
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
Reputation: 6251
and adjust your cell row height here -
viewDidLoad
tableView.estimatedRowHeight = 100.0 // Adjust Primary table height
tableView.rowHeight = UITableViewAutomaticDimension //This line adjust cell height according to containts
UITableViewAutomaticDimension
to UITableView.automaticDimension
tableView.estimatedRowHeight = 100.0 // Adjust Primary table height
tableView.rowHeight = UITableView.automaticDimension
Upvotes: 13
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
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.
Upvotes: 4