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

标题: ios - 在 Tableview Swift 中删除 Header View Section 的白色边框底部 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:05
标题: ios - 在 Tableview Swift 中删除 Header View Section 的白色边框底部

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

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

    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 = "roduktet 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()
        }

    }

enter image description here



Best Answer-推荐答案


试试这个:

cell.separatorInset = UIEdgeInsetsZero
cell.layoutMargins = UIEdgeInsetsZero

关于ios - 在 Tableview Swift 中删除 Header View Section 的白色边框底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50108139/






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