Xcode Storyboard - Where to set UITableViewCell height

瘦欲@ 提交于 2021-02-10 05:48:05

问题


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 to UITableView.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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!