问题
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?
回答1:
Click on Table View after that click on Size Inspector
and adjust your cell row height 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
toUITableView.automaticDimension
tableView.estimatedRowHeight = 100.0 // Adjust Primary table height
tableView.rowHeight = UITableView.automaticDimension
回答2:
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.
回答3:
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
}
回答4:
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
}
来源:https://stackoverflow.com/questions/37651967/xcode-storyboard-where-to-set-uitableviewcell-height