Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在“中绘制分隔符”;“中”;两个部分的空间?_Ios_Swift - Fatal编程技术网

Ios 如何在“中绘制分隔符”;“中”;两个部分的空间?

Ios 如何在“中绘制分隔符”;“中”;两个部分的空间?,ios,swift,Ios,Swift,我希望在UITableView中使用以下条件绘制分隔符 单元格项之间没有分隔符 各部分之间有一个分隔符 各部分之间应留有空间 段之间的分隔符,应该画在剖面空间的中间。 在Android应用程序中,这就是我们想要的外观 但是,当我们在UITableViewController中实现此功能时,我们很难在节空间的中间绘制分隔符 这就是我们的iOS应用程序的外观 下面是自定义代码,它尝试在节之间绘制分隔符 override func tableView(_ tableView: UITable

我希望在
UITableView
中使用以下条件绘制分隔符

  • 单元格项之间没有分隔符
  • 各部分之间有一个分隔符
  • 各部分之间应留有空间
  • 段之间的分隔符,应该画在剖面空间的中间。
在Android应用程序中,这就是我们想要的外观


但是,当我们在
UITableViewController
中实现此功能时,我们很难在节空间的中间绘制分隔符

这就是我们的iOS应用程序的外观

下面是自定义代码,它尝试在节之间绘制分隔符

override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    // UIView with darkGray background for section-separators as Section Footer
    let v = UIView(frame: CGRect(x: 0, y:0, width: tableView.frame.width, height: 1))
    v.backgroundColor = .darkGray
    return v
}

override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    // Section Footer height
    return 1.0
}

结果并不完美。如您所见,分隔符不是位于“垃圾桶”和“设置”的中间,而是关闭为“垃圾桶”


基础数据结构 我们的实现非常简单。如下所示

private static let noteSection = [
    SideMeu(
        stringResource: "nav_notes",
        image: UIImage(systemName: "note")!
    )
]

private static let archiveSection = [
    SideMeu(
        stringResource: "nav_archive",
        image: UIImage(systemName: "archivebox")!
    ),
    SideMeu(
        stringResource: "nav_trash",
        image: UIImage(systemName: "trash")!
    )
]

private static let settingsSection = [
    SideMeu(
        stringResource: "nav_settings",
        image: UIImage(systemName: "gear")!
    ),
    SideMeu(
        stringResource: "nav_feedback",
        image: UIImage(systemName: "exclamationmark.bubble")!
    ),
    SideMeu(
        stringResource: "nav_shop",
        image: UIImage(systemName: "cart")!
    )
]

static let sections = [
    noteSection,
    archiveSection,
    settingsSection
]

override func numberOfSections(in tableView: UITableView) -> Int {
    return SideMenuTableViewController.sections.count
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    let s = SideMenuTableViewController.sections[section]
    return s.count
}


override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath)

    let s = SideMenuTableViewController.sections[indexPath.section]
    let item = indexPath.item
    let sideMenu = s[item]
    
    cell.textLabel?.text = sideMenu.stringResource.localized
    cell.imageView?.image = sideMenu.image
    
    return cell
}


你有什么想法,我们如何能有一个很好的分隔符,画在“中间”的两个部分的空间?谢谢。

请将ViewForFooterInstitution中的y位置更改为10,然后再试一次。否则,您可以设置
contentinset
,我认为这是最好的解决方案。检查此处的插图:如果您想使用
ViewForFooterInstitution
,我也会使用
ViewForHeaderInstitution
部分:页眉高度为5,页脚高度为5并带有“黑线”而不是1像素(正确放置)。您当前的设置(高度为1和黑色)生成当前结果,这是正常的,不是吗?