OGeek|极客世界-中国程序员成长平台

标题: ios - Tableview 的 contentView 小于 tableview 框架和单元格 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:01
标题: ios - Tableview 的 contentView 小于 tableview 框架和单元格

我正在使用以下代码以编程方式创建一个 Tableview:

 override func viewDidLayoutSubviews() {
    //@begin store selection - settings
    self.tbStores = UITableView(frame: CGRect(x: 15, y: 60, width: UIScreen.main.bounds.size.width - 30, height: 150))
    self.tbStores.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
    tbStores.backgroundColor = UIColor.white
    tbStores.delegate = self
    tbStores.dataSource = self
    tbStores.allowsSelection = true;
    tbStores.translatesAutoresizingMaskIntoConstraints = true
 }

并添加以编程方式创建的 ViewAutoComplete

if (viewAutoComplete == nil) {
            self.viewAutoComplete = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height))
            viewAutoComplete.backgroundColor = UIColor(red: 32 / 255.0, green: 48 / 255.0, blue: 90 / 255.0, alpha: 1)
            viewAutoComplete.alpha = 1
            viewAutoComplete.translatesAutoresizingMaskIntoConstraints = true
            self.viewAutoComplete.tag = 123
    self.view!.addSubview(viewAutoComplete)
            viewAutoComplete.addSubview(tbStores)
}

问题是 contentView 比 cell 和 tableview 小,如下图所示

enter image description here

enter image description here



Best Answer-推荐答案


我解决了我的问题

iOS 8 UITableView separator inset 0 not working关于分隔符插入的说明

我刚刚将以下代码添加到我的 viewDidLayoutSubviews

tbStores.cellLayoutMarginsFollowReadableWidth = false;

关于ios - Tableview 的 contentView 小于 tableview 框架和单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40530353/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4