热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Xcode7ios9UITableViewCell分隔符嵌套问题-Xcode7iOS9UITableViewCellSeparatorInsetissue

Thisisnotaquestion,ratherasolutiontotheproblemIfaced.这不是一个问题,而是我面临的问题的解决方案。InXcode7

This is not a question, rather a solution to the problem I faced.

这不是一个问题,而是我面临的问题的解决方案。

In Xcode 7, when the application is run on iOS 9 on iPad devices, the UITableView cells leave some margin onto the left side of the tableview. And rotating the device to landscape would increase the margins.

在Xcode 7中,当应用程序在iPad设备的iOS 9上运行时,UITableView单元格会在tableview的左侧留下一些空白。而将设备旋转到横向将增加边缘。

The solution I found is:

我找到的解决方法是:

Setting "cellLayoutMarginsFollowReadableWidth" to NO.

设置“cellLayoutMarginsFollowReadableWidth”没有。

self.tbl_Name.cellLayoutMarginsFollowReadableWidth = NO;

Since, this property is only available in iOS 9. So, you will have to put a condition to check the iOS version, else it will crash.

因为这个属性只在ios9中可用。所以,你需要设置一个条件来检查iOS版本,否则它会崩溃。

if(NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_8_1)
{
    self.tbl_Name.cellLayoutMarginsFollowReadableWidth = NO;
}

Hope it is helpful to others.

希望它对别人有帮助。

4 个解决方案

#1


38  

Best Solution for iOS 9 and above

iOS 9及以上版本的最佳解决方案

This is because of a new feature called readable content guides. It provides margins that are suitable for reading. So, in iPhone and portrait iPad they are very small margins, but in landscape iPad they are bigger. In iOS 9, UITableView's cell margins default to following the readable content guide.

这是因为一种叫做可读内容指南的新特性。它提供适合阅读的边距。因此,在iPhone和竖屏iPad中,它们的利润率很小,但在横向iPad中,它们更大。在ios9中,UITableView的单元格页边值默认遵循可读内容指南。

If you want to stop that, just set the tableView's cellLayoutMarginsFollowReadableWidth to NO/false.

如果您想停止该操作,只需将tableView的celllayout边缘性页面宽度设置为NO/false。

Source: https://forums.developer.apple.com/thread/5496

来源:https://forums.developer.apple.com/thread/5496

#2


13  

Perfect Solution upto iOS 9

iOS 9的完美解决方案

In viewDidLoad

在viewDidLoad

Objective-C

objective - c

- (void)viewDidLoad {
    [super viewDidLoad];
    //Required for iOS 9
    if ([[[UIDevice currentDevice]systemVersion]floatValue] >= 9.0) {
        self.testTableView.cellLayoutMarginsFollowReadableWidth = NO;
    }
}

Swift

斯威夫特

 override func viewDidLoad() {
    super.viewDidLoad()
    if #available(iOS 9.0, *) {
      tableViewDiet.cellLayoutMarginsFollowReadableWidth = false
    }
  }

In TableViewDelegate methods add following code:

在TableViewDelegate方法中添加以下代码:

Objective-C

objective - c

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

    // Remove seperator inset
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }

    // Prevent the cell from inheriting the Table View's margin settings
    if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
        [cell setPreservesSuperviewLayoutMargins:NO];
    }

    // Explictly set your cell's layout margins
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

Swift

斯威夫特

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {

    // Remove seperator inset
    if cell.respondsToSelector(Selector("setSeparatorInset:")) {
      cell.separatorInset = UIEdgeInsetsZero
    }

    // Prevent the cell from inheriting the Table View's margin settings
    if cell.respondsToSelector(Selector("setPreservesSuperviewLayoutMargins:")) {
      cell.preservesSuperviewLayoutMargins = false
    }

    // Explictly set your cell's layout margins
    if cell.respondsToSelector(Selector("setLayoutMargins:")) {
      cell.layoutMargins = UIEdgeInsetsZero
    }
  }

#3


3  

A little bit late. I hope is helpful for someone else...

有点晚了。我希望对其他人有所帮助……

if #available(iOS 9.0, *) {
      myTableView.cellLayoutMarginsFollowReadableWidth = false
}

#4


0  

readableContentGuide is a layout guide that is already added to every UIView

readableContentGuide是一个布局指南,已经添加到每个UIView

This is to ensure the user doesn't have to turn his head to read the content.

这是为了确保用户不必转过头来阅读内容。

If you want to follow the readable content guide, then do following:

如果您想要遵循可读的内容指南,那么请执行以下操作:

let baseSection = UIView()

contentView.addSubview(baseSection)

baseSection.translatesAutoresizingMaskIntoCOnstraints= false

let insets = UIEdgeInsets(top: 4, left: 0, bottom: 4, right: 0)

baseSection.leadingAnchor.constraint(equalTo: readableContentGuide.leadingAnchor, constant: insets.left).isActive = true
baseSection.trailingAnchor.constraint(equalTo: readableContentGuide.trailingAnchor, constant: -insets.right).isActive = true
baseSection.topAnchor.constraint(equalTo: contentView.topAnchor, constant: insets.top).isActive = true
baseSection.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -insets.bottom).isActive = true

Note: In the code above the bottom and top anchors use the contentView instead of the readableContentGuide so that the content vertical margins changes based on the tableView.rowHeight.

注意:在底部和顶部的代码中,使用contentView而不是readableContentGuide,以使内容垂直的边距根据tableview而变化。


推荐阅读
  • Scala 实现 UTF-8 编码属性文件读取与克隆
    本文介绍如何使用 Scala 以 UTF-8 编码方式读取属性文件,并实现属性文件的克隆功能。通过这种方式,可以确保配置文件在多线程环境下的一致性和高效性。 ... [详细]
  • 本文深入探讨了 Java 中的 Serializable 接口,解释了其实现机制、用途及注意事项,帮助开发者更好地理解和使用序列化功能。 ... [详细]
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • Explore how Matterverse is redefining the metaverse experience, creating immersive and meaningful virtual environments that foster genuine connections and economic opportunities. ... [详细]
  • Explore a common issue encountered when implementing an OAuth 1.0a API, specifically the inability to encode null objects and how to resolve it. ... [详细]
  • DNN Community 和 Professional 版本的主要差异
    本文详细解析了 DotNetNuke (DNN) 的两种主要版本:Community 和 Professional。通过对比两者的功能和附加组件,帮助用户选择最适合其需求的版本。 ... [详细]
  • c# – UWP:BrightnessOverride StartOverride逻辑 ... [详细]
  • 本文详细介绍了Java中org.eclipse.ui.forms.widgets.ExpandableComposite类的addExpansionListener()方法,并提供了多个实际代码示例,帮助开发者更好地理解和使用该方法。这些示例来源于多个知名开源项目,具有很高的参考价值。 ... [详细]
  • 使用 Azure Service Principal 和 Microsoft Graph API 获取 AAD 用户列表
    本文介绍了一段通用代码示例,该代码不仅能够操作 Azure Active Directory (AAD),还可以通过 Azure Service Principal 的授权访问和管理 Azure 订阅资源。Azure 的架构可以分为两个层级:AAD 和 Subscription。 ... [详细]
  • Android 渐变圆环加载控件实现
    本文介绍了如何在 Android 中创建一个自定义的渐变圆环加载控件,该控件已在多个知名应用中使用。我们将详细探讨其工作原理和实现方法。 ... [详细]
  • UNP 第9章:主机名与地址转换
    本章探讨了用于在主机名和数值地址之间进行转换的函数,如gethostbyname和gethostbyaddr。此外,还介绍了getservbyname和getservbyport函数,用于在服务器名和端口号之间进行转换。 ... [详细]
  • 本文详细解析了Python中的os和sys模块,介绍了它们的功能、常用方法及其在实际编程中的应用。 ... [详细]
  • RecyclerView初步学习(一)
    RecyclerView初步学习(一)ReCyclerView提供了一种插件式的编程模式,除了提供ViewHolder缓存模式,还可以自定义动画,分割符,布局样式,相比于传统的ListVi ... [详细]
  • 本教程涵盖OpenGL基础操作及直线光栅化技术,包括点的绘制、简单图形绘制、直线绘制以及DDA和中点画线算法。通过逐步实践,帮助读者掌握OpenGL的基本使用方法。 ... [详细]
  • 基因组浏览器中的Wig格式解析
    本文详细介绍了Wiggle(Wig)格式及其在基因组浏览器中的应用,涵盖variableStep和fixedStep两种主要格式的特点、适用场景及具体使用方法。同时,还提供了关于数据值和自定义参数的补充信息。 ... [详细]
author-avatar
平凡无琦世界
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有