Добавьте эту строку, чтобы удалить разделительную линию
tableView.separatorStyle = .none
И добавьте одну метку (здесь я добавил lblCafes
) в UITableViewCell
и установите цвет фона метки в оранжевый цвет.
Ваш код будет,
class CafesView: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
let cafes = [
"Banana Joe's",
"College Eight Cafe",
"Global Village",
"Iveta",
"Stevenson Coffee House",
"Terra Fresca",
"Vivas"
]
override func viewDidLoad() {
super.viewDidLoad()
tableView.separatorStyle = .none
tableView.delegate = self
tableView.dataSource = self
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 7
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cafesCell = tableView.dequeueReusableCell(withIdentifier: "cafeCell", for: indexPath) as? TableViewCell
cafesCell?.lblCafes?.text = cafes[indexPath.row]
return cafesCell ?? UITableViewCell()
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return tableView.frame.height / 7
}
@IBAction func closeTapped(_ sender: UIButton) {
self.dismiss(animated: true, completion: nil)
}
}
class TableViewCell: UITableViewCell {
@IBOutlet weak var lblCafes: UILabel!
override func layoutSubviews() {
super.layoutSubviews()
self.lblCafes.backgroundColor = .systemOrange
self.roundCorners(corners: [.topLeft, .bottomLeft], radius: 10)
}
}