【问题标题】:Remove the white border bottom of Header View Section in Tableview Swift删除 Tableview Swift 中标题视图部分的白色边框底部
【发布时间】:2018-04-30 20:59:51
【问题描述】:

我将 Storyboard 中的分隔符样式删除为 none,但标题视图底部仍显示 1px 白色边框。 我尝试将 viewdidload 上的分隔符样式设置为 none,并尝试使用一些扩展来删除子视图,但仍然不起作用。

我使用一个单元格在我的标题视图中出列并为其设置高度。 这是我的代码:

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        switch section {
        case 0:
            return 1
        case 1:
            return 1
        case 2:
            return 1
        case 3:
            return 1
        case 4:
            return 1
        case 5:
            return 1
        case 6:
            return 1
        default:
            return 1
        }
    }

    // MARK: - View For Header

    override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        switch section {
        case 2:

            let cell = tableView.dequeueReusableCell(withIdentifier: "NewProductHeaderTableViewCell") as! NewProductHeaderTableViewCell
            tableView.separatorStyle = UITableViewCellSeparatorStyle.none
            cell.titleLabel.text = "Produktet e reja"
            return cell
        case 3:
            let cell = tableView.dequeueReusableCell(withIdentifier: "NewProductHeaderTableViewCell") as! NewProductHeaderTableViewCell
            cell.titleLabel.text = "Top Produktet"
            return cell
        case 4:
            let cell = tableView.dequeueReusableCell(withIdentifier: "NewProductHeaderTableViewCell") as! NewProductHeaderTableViewCell
            cell.titleLabel.text = "Me te shiturat"
            return cell
        default:
            return nil
        }
    }

    // MARK: - Height For Header

    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        switch section {
        case 2:
            return 46.0
        case 3:
            return 46.0
        case 4:
            return 46.0
        default:
            return 0.1
        }
    }

    override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0
    }

    // MARK: - Height For Row

    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        switch indexPath.section {
        case 0:
            return 90
        case 1:
            return UITableViewAutomaticDimension
        case 2:
            return 177
        case 3:
            return 177
        case 4:
            return UITableViewAutomaticDimension
        case 5:
            return 90
        case 6:
            return 90
        default:
            return 90
        }
    }

    // MARK: - Cell For Row

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        switch indexPath.section {
        case 0:
            let cell = tableView.dequeueReusableCell(withIdentifier: "StoryTableViewCell", for: indexPath) as! StoryTableViewCell
            return cell
        case 1:
            return UITableViewCell()
        case 2:
            let cell = tableView.dequeueReusableCell(withIdentifier: "NewProductTableViewCell", for: indexPath) as! NewProductTableViewCell
            return cell
        case 3:
            let cell = tableView.dequeueReusableCell(withIdentifier: "NewProductTableViewCell", for: indexPath) as! NewProductTableViewCell
            return cell
        case 4:
            return UITableViewCell()
        case 5:
            return UITableViewCell()
        case 6:
            return UITableViewCell()
        default:
            return UITableViewCell()
        }

    }

【问题讨论】:

  • 这可能无法解决您的问题,但您始终可以将背景颜色更改为相同的灰色。我知道这是您想要的答案,但在您找到答案之前只是一种选择

标签: ios swift


【解决方案1】:

试试这个:

cell.separatorInset = UIEdgeInsetsZero
cell.layoutMargins = UIEdgeInsetsZero

【讨论】:

  • 感谢您的回答,它是 UIEdgeInsets.zero 但仍然无法正常工作
【解决方案2】:

试试这个

   override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    switch section {
    case 2:

        let cell = tableView.dequeueReusableCell(withIdentifier: "NewProductHeaderTableViewCell") as! NewProductHeaderTableViewCell
        tableView.separatorStyle = UITableViewCellSeparatorStyle.none
        cell.titleLabel.text = "Produktet e reja"
        return cell
    case 3:
        let cell = tableView.dequeueReusableCell(withIdentifier: "NewProductHeaderTableViewCell") as! NewProductHeaderTableViewCell
        cell.titleLabel.text = "Top Produktet"
        return cell
    case 4:
        let cell = tableView.dequeueReusableCell(withIdentifier: "NewProductHeaderTableViewCell") as! NewProductHeaderTableViewCell
        cell.titleLabel.text = "Me te shiturat"
        return cell
    default:
        let view = UIView(frame: .zero)
        view.backgroundColor = .clear
        return view
    }
}

【讨论】:

    猜你喜欢
    • 2011-12-18
    • 2015-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-25
    • 2018-09-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多