如何在 UITableView
中创建单行 View 分隔符,如 Android 的 NavigationDrawer:
我知道在 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/