更改tableView分隔符insets

时间:2015-08-24 09:22:54

标签: ios uitableview delegates cell

我在定制我的手机时遇到了一些问题;

enter image description here

你可以看到分隔线没有到达单元格的左边界,我想要这样做。我找到了这些:

任何人都可以帮我翻译快速代码吗?

5 个答案:

答案 0 :(得分:11)

转换Swift中的答案(Separator lines for UITableViewCellStyleSubtitle cells not taking the full width

enter image description here

let floatVersion = (UIDevice.currentDevice().systemVersion as NSString).floatValue

if (floatVersion > 8.0){
    cell.layoutMargins = UIEdgeInsetsZero
    cell.preservesSuperviewLayoutMargins = false
}

通过检查版本号:

viewHolder.swipeLayout.getSurfaceView().setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(mContext, " onClick : " + item.getName() + " \n" + item.getEmailId(), Toast.LENGTH_SHORT).show();
        }
    });

答案 1 :(得分:3)

第二个链接应该有用。

swift版本:

verify(conversationService).addState(Matchers.<ID<Document>>any());

答案 2 :(得分:3)

斯威夫特3:

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    if (cell.responds(to: #selector(setter: UITableViewCell.separatorInset))) {
        cell.separatorInset = UIEdgeInsets.zero
    }

    if (cell.responds(to: #selector(setter: UIView.preservesSuperviewLayoutMargins))) {
        cell.preservesSuperviewLayoutMargins = false
    }

    if (cell.responds(to: #selector(setter: UIView.layoutMargins))) {
        cell.layoutMargins = UIEdgeInsets.zero
    }
}

答案 3 :(得分:2)

cellForRowAtIndePath方法中添加以下行:

    if cell.respondsToSelector("setSeparatorInset:") {
        cell.separatorInset = UIEdgeInsetsZero
    }
    if cell.respondsToSelector("setLayoutMargins:") {
        cell.layoutMargins = UIEdgeInsetsZero
    }
    if cell.respondsToSelector("setPreservesSuperviewLayoutMargins:") {
        cell.preservesSuperviewLayoutMargins = false
    }

希望这有助于......:)

答案 4 :(得分:1)

这是旧版本,它不再适用。

cell.layoutMargins = UIEdgeInsetsZero
cell.preservesSuperviewLayoutMargins = false

你可以使用它(对于swift,在Objective C中你可以调用相同的东西)

cell.separatorInset = UIEdgeInsets.zero
相关问题