Xcode Storyboard - 在哪里设置UITableViewCell高度

问题描述 投票:0回答:3

我正在使用Xcode 7,我试图在故事板设置中设置UITableViewCell的高度,以便为不同的设备提供不同的单元格高度(例如,普通和紧凑x常规)。

我找不到这些设置的地方。这只能通过编程方式实现吗?

xcode swift uitableview uistoryboard
3个回答
5
投票

单击Size Inspector后单击Table View

并调整你的细胞行高度 -

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

  • 你需要从UITableViewAutomaticDimension改为UITableView.automaticDimension

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

1
投票

转到故事板,找到表格视图并选择单元格。您会注意到单元格底部中间有一个白色方块。您可以拖动它来更改单元格高度。

Change cell height


0
投票

您可以这种方式设置UITableView高度。尝试此代码

 - (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
}
© www.soinside.com 2019 - 2024. All rights reserved.