簡體   English   中英

在 UITableView 之間添加分段分隔符

[英]Add a Section Separator Between UITableView

第一個(左)是我的設計,第二個(右)是我現在已經取得的成果。 一個區別是,對於第二張圖像,我沒有像第一張那樣的分隔線。 viewForFooterInSection我已經嘗試了許多現有的解決方案來顯示分隔線,但沒有得到確切的解決方案。 我需要在第一部分和第二部分的最后一行末尾有分隔線,並留有一些空間。

在此處輸入圖像描述

這是我的代碼 -

func numberOfSections(in tableView: UITableView) -> Int {
    return secName.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return items[section].count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    
    let cell = tableView.dequeueReusableCell(withIdentifier: "APHomeTableViewCell", for: indexPath) as! APHomeTableViewCell
    cell.selectionStyle = .none
    cell.cellTitle.text = items[indexPath.section][indexPath.row]
    return cell
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    return self.secName[section]
}


func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    self.tableView.backgroundColor = UIColor.white
    let headerFrame = tableView.frame
    
    let title = UILabel()
    title.frame =  CGRect(x: 40, y: 0, width: headerFrame.size.width-20, height: 40)
    title.font = UIFont.SFBoldFont(ofSize: 14)//UIFont(name: "Futura", size: 30)!
    title.text = self.tableView(tableView, titleForHeaderInSection: section)
    title.textColor = UIColor(white: 0.19, alpha: 1.0)//UIColor(red: 34/255.0, green: 141/255.0, blue: 183/255.0, alpha: 1.0)
    
    let headerView:UIView = UIView(frame: CGRect(x: 0, y: 0, width: headerFrame.size.width, height: headerFrame.size.height))
    headerView.addSubview(title)
    
    return headerView
}


func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 45
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    let section = indexPath.section
    return 70
}

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

你可以做一點改變

轉動

111

4444

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM