Fab*_*nni 3 delegates cell uitableview ios
我在定制我的手机时遇到了一些问题;
你可以看到分隔线没有到达单元格的左边界,我想这样做.我找到了这些:
任何人都可以帮我翻译快速代码吗?
Ash*_*kad 11
用于在Swift中转换答案(UITableViewCellStyleSubtitle单元格的分隔线不占用整个宽度)
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("yourcell") as! UITableViewCell
if (cell.respondsToSelector("setPreservesSuperviewLayoutMargins:")){
cell.layoutMargins = UIEdgeInsetsZero
cell.preservesSuperviewLayoutMargins = false
}
}
Run Code Online (Sandbox Code Playgroud)
通过检查版本号:
let floatVersion = (UIDevice.currentDevice().systemVersion as NSString).floatValue
if (floatVersion > 8.0){
cell.layoutMargins = UIEdgeInsetsZero
cell.preservesSuperviewLayoutMargins = false
}
Run Code Online (Sandbox Code Playgroud)
小智 5
这是旧版本,不再起作用了。
cell.layoutMargins = UIEdgeInsetsZero
cell.preservesSuperviewLayoutMargins = false
Run Code Online (Sandbox Code Playgroud)
你可以使用这个(对于 swift,在 Objective C 中你可以调用同样的东西)
cell.separatorInset = UIEdgeInsets.zero
Run Code Online (Sandbox Code Playgroud)
斯威夫特 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
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12575 次 |
| 最近记录: |