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

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

内容简介:翻译自: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


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

查看所有标签

猜你喜欢:

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

Data Mining

Data Mining

Jiawei Han、Micheline Kamber、Jian Pei / Morgan Kaufmann / 2011-7-6 / USD 74.95

The increasing volume of data in modern business and science calls for more complex and sophisticated tools. Although advances in data mining technology have made extensive data collection much easier......一起来看看 《Data Mining》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

随机密码生成器
随机密码生成器

多种字符组合密码