Grouped UITableView has 20px of extra padding at the bottom

前端 未结 12 1119
长发绾君心
长发绾君心 2020-12-23 09:34

Grouped table views seem to have extra padding on the bottom in iOS 6 (iOS 5 does not have it), but I can\'t find any documentation that suggests this is correct / expected

相关标签:
12条回答
  • 2020-12-23 09:48

    Swift 3 code

    class PaddingLessTableView : UITableView
    {
        override func layoutSubviews() {
            self.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
            super.layoutSubviews()
        }
    }
    
    0 讨论(0)
  • 2020-12-23 09:49

    this solves the issue:

    Obj-c

    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
            return 0.1;
        }
    

    Swift:

    override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.1
    }
    
    0 讨论(0)
  • 2020-12-23 09:53

    This is the only working solution I guess.I tried setting tableFooterView and tableHeaderView to nil. But nothing happened.Then the following solution worked .Returning zero "return 0;" has no effect.We should return the lowest possible height.

     - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
            return CGFLOAT_MIN;
        }
    
     - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
            return CGFLOAT_MIN;
        }
    

    NOTE: This is what I got when printed the values.

    CGFLOAT_MAX = 340282346638528859811704183484516925440.000000

    CGFLOAT_MIN = 0.000000

    0 讨论(0)
  • 2020-12-23 09:57

    In Swift 4.2 you can try setting table header with least normal magnitude height -

    var frame = CGRect.zero
    frame.size.height = .leastNormalMagnitude
    tableView.tableHeaderView = UIView(frame: frame)
    
    0 讨论(0)
  • 2020-12-23 09:59

    @frankWhite' solution works great, but here is a better solution to avoid typing 0.1, 0.001 or others to make it less ambiguous.

    // Swift version
    func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    
        // remove bottom extra 20px space.
        return CGFloat.min
    }
    
    // Objective-C version
    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
        // remove bottom extra 20px space.
        return CGFLOAT_MIN;
    } 
    
    0 讨论(0)
  • 2020-12-23 10:03

    in Swift 3

    override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return CGFloat.leastNormalMagnitude
    }
    
    0 讨论(0)
提交回复
热议问题