ios – 如何在Swift中删除左侧的UITableView偏移量

栏目: Swift · 发布时间: 7年前

内容简介:翻译自:https://stackoverflow.com/questions/24748025/how-to-remove-uitableview-offset-on-the-left-in-swift

我找到了一些问题和答案来删除ios7中UITableViews的偏移量,即这里的这个

How to fix UITableView separator on iOS 7?

我想知道是否有人遇到了正确的功能来删除插入边距.在objective-c中类似于这个答案的东西

if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
    [tableView setSeparatorInset:UIEdgeInsetsZero];
}

就像Objective-C示例一样,但转换为swift.我自己遇到了一些麻烦.如果您在UITableViewController中执行此代码,则此代码在UITableView中工作,您可以将self.tableView替换为self:

// iOS 7
if(self.respondsToSelector(Selector("setSeparatorInset:"))){
    self.separatorInset = UIEdgeInsetsZero
}

// iOS 8
if(self.respondsToSelector(Selector("setLayoutMargins:"))){
    self.layoutMargins = UIEdgeInsetsZero;
}

对于单元格(仅限iOS 8),将以下代码放在以下函数中:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)

获取单元格,并设置以下属性:

// iOS 8
if(cell.respondsToSelector(Selector("setLayoutMargins:"))){
    cell.layoutMargins = UIEdgeInsetsZero;
}

翻译自:https://stackoverflow.com/questions/24748025/how-to-remove-uitableview-offset-on-the-left-in-swift


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Pattern Recognition and Machine Learning

Pattern Recognition and Machine Learning

Christopher Bishop / Springer / 2007-10-1 / USD 94.95

The dramatic growth in practical applications for machine learning over the last ten years has been accompanied by many important developments in the underlying algorithms and techniques. For example,......一起来看看 《Pattern Recognition and Machine Learning》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

html转js在线工具
html转js在线工具

html转js在线工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具