【发布时间】:2015-02-22 08:27:06
【问题描述】:
我正在实现一个功能,其中我的单元格的所有标签都已根据每个标签包含的文本调整大小。我在RayWanderlich tutorial 的帮助下实现了此功能,它在 iPhone 4s、5 和 5s 上运行良好使用 iOS 8.1。如下图所示,它显示了 iOS 8.1 的 iPhone 5s 模拟器
当我使用 iPhone 6 或 iPhone 6 plus 运行我的应用程序时,我遇到了如下图所示的意外行为,该图显示了 iPhone 6 模拟器
和iPhone 6 plus 模拟器。
我创建了两个自定义单元笔尖文件,一个用于 iPhone 4、4s、5 和 5s,第二个用于 iPhone 6 和 6 plus。因为我是自动布局的新手,所以我设置了两个笔尖相同的约束。我在下面的图像中显示了具有设置约束的两个自定义单元格 nib 文件。
iPhone 4、4s、5 和 5s 笔尖文件快照
iPhone 6 和 iPhone 6 plus 自定义单元笔尖文件快照
我还使用了以下代码 sn-p,其中单元格已使用动态高度调整大小。该代码适用于 iPhone iPhone 4(适用于 iOS 7)、4s、5 和 5s(适用于 iOS 7 和 iOS 8 和 8.1),但不适用于 iPhone 6 和 iPhone 6 plus。
代码片段
- (CGFloat)calculateHeightForConfiguredSizingCell_3:(MemberListTableViewCell_WithoutImage_3_iPhone *)sizingCell {
sizingCell.bounds = CGRectMake(0.0f, 0.0f, CGRectGetWidth(self.tblView.frame), CGRectGetHeight(sizingCell.bounds));
[sizingCell setNeedsLayout];
[sizingCell layoutIfNeeded];
CGSize size = [sizingCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
//CGSize size = [sizingCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize withHorizontalFittingPriority:UILayoutPriorityDefaultHigh verticalFittingPriority:UILayoutPriorityDefaultHigh];
return size.height + 1.0f; // Add 1.0f for the cell separator height
}
请给我一个正确的解决方案,我哪里出错了。我浏览了很多东西,但无法找到解决这个问题的正确方法。您的帮助将不胜感激。在此先感谢。
【问题讨论】:
标签: ios uilabel autolayout nslayoutconstraint custom-cell