ios - 如何在 UITableView 中创建单行 View 分隔符

标签 ios swift uitableview uiviewcontroller

如何在 UITableView 中创建单行 View 分隔符,如 Android 的 NavigationDrawer:

enter image description here

我知道在 Android 中这很容易,但我找不到 iOS 的引用,它在 iOS 上如何调用,我只想在我的菜单 View 中有一个单行分隔符,我的所有视频和教程可以找到 iOS 显示如何添加可扩展菜单,这不是我想要的,我只想要一行分隔两组字符串数组。这在 iOS 上可行吗?我在哪里可以找到相关教程?

到目前为止我的代码:

import UIKit

class MenuViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    //Outlets
    @IBOutlet weak var tableView: UITableView!
    var menuNameArr = [String]()
    var iconImage = [UIImage]()

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.alwaysBounceVertical = false;
        tableView.separatorStyle = .none

        menuNameArr = ["Meu Perfil", "Meus Cupons", "Extrato de pontos", "Configurações", "Termos de uso", "Entre em Contato", "Avaliar aplicativo", "Sair"]
        iconImage = [UIImage(named: "user")!,UIImage(named: "cupons")!, UIImage(named: "extrato")!, UIImage(named: "config")!, UIImage(named: "termos")!, UIImage(named: "contato")!, UIImage(named: "avaliar")!, UIImage(named: "sair")!]
        self.revealViewController().rearViewRevealWidth = self.view.frame.size.width - 60
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return menuNameArr.count
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "MenuTableViewCell") as! MenuTableViewCell

        cell.imgIcon.image = iconImage[indexPath.row]
        cell.lblMenuName.text! = menuNameArr[indexPath.row]
        return cell
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    }


}

从“Configurações”到“Sair”,我希望数组的那部分成为菜单的第二部分

最佳答案

试试这个

    if indexPath.row == 3{
        let separator = UILabel(frame: CGRect(x: 15, y: cell.frame.size.height - 1, width: cell.frame.size.width, height: 1))
        separator.backgroundColor = UIColor.red
        cell.contentView.addSubview(separator)
    }

关于ios - 如何在 UITableView 中创建单行 View 分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49397832/

相关文章:

ios - 存储在 UITextField 上的 Realm 数据为空,print(entry) 有效

android - 从 phonegap 重启设备

ios - Xib 和 Storyboard

iphone - 为什么使用 UINib 将 customCell 属性设置为 nil

ios - UITableViewRowAction 标题作为图像图标而不是文本

ios - AES 加密到奇怪的字符

ios - 对齐边距 xcode 7.0 灰色,无边距限制更新

swift - TabView 的 TabItem 的选定选项卡图像在 SwiftUI 中始终为蓝色

swift - 如何向枚举添加新案例?

ios - 对同一自定义单元格使用不同的重用标识符