如何在Swift的UITableview中为分隔符插入固定宽度?

问题描述 投票:0回答:2

我在Swift中使用Xcode7.3.1。我的视图控制器由UITableView组成,我需要使用默认单元格为分隔符插入设置固定宽度。请仔细阅读下图。如何解决此问题?

enter image description here

ios swift xcode uitableview
2个回答
0
投票

尝试在tableview中设置分隔符的插入,如下面的截图:

enter image description here

以编程方式:

    cell.separatorInset = UIEdgeInsetsMake(0, 15, 0, cell.frame.width/2) // modify width as per your need

0
投票

如果您正在使用自定义单元格,则在具有固定宽度约束的单元格的contentView中添加UILabelUIImageView

例如,以下约束将使分隔符固定宽度

Leading - 10
Bottom - 2
Fixed Width - 100 (In my case)
Fixed height - 1

注意:将默认分隔符样式设为无

self.tblView.separatorStyle = UITableViewCellSeparatorStyle.None;

或者你也可以在故事板中设置它。

看我的输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.