iphone - 继续在 UITableView 的 "bounce area"中交替行颜色

标签 iphone uitableview uikit

在 iPhone 上的 Weather.app 中,滚动超过每小时表格 View 的边界会继续显示交替的表格单元格,只是其中没有任何文本(见下图)。我想知道如何复制这种外观。 This question提供了一个解决方案,但我希望有一种更有效的方法,而不是在表格 View 上方添加空白单元格的图像。

谢谢

enter image description here

最佳答案

您可以使用 UITableView 的 headerViewfooterView 属性。这些允许您指定将放置在内容单元格之前和之后的自定义 UIView。

因此,您应该使用一些具有交替颜色的虚拟内部 View 来初始化 UIView。此 UIView 的高度应等于 tableView.frame.size.height。然后就这样做:


tableView.headerView = headerViewWithFakeColors;
tableView.footerView = footerViewWithFakeColors;

此外,您还需要更改 contentInset 属性,以便这些假页眉和页脚 View 仅在用户弹跳时可见(使用 contentInset 您可以控制 tableview 开始弹跳的点)


tableView.contentInset = UIEdgeInsetsMake(headerViewWithFakeColors.frame.size.height, 0, -footerViewWithFakeColors.frame.size.height, 0);

关于iphone - 继续在 UITableView 的 "bounce area"中交替行颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8771504/

相关文章:

ios - 滚动到 UITableView 的底部(UITableView 在 UITableViewCell 中)

ios - 在 Mac Catalyst 中打开一个新窗口

iphone - 我的 UITableViewCell 中的 UIImageView 在单击时更改大小

ios - 自定义 UITableViewCells 重叠?

ios - 集合单元格内容大小

ios - 从 XIB 创建的 UICollectionViewCell 在拖放过程中会导致闪烁

iphone - 如何给 UILabel 添加效果

iphone - NSURLConnection 在我得到 Error Domain=NSPOSIXErrorDomain Code=57 后不会响应

iphone - iPhone 模拟器 4.0 中 Home 按钮无法退出应用程序

iphone - YouTube视频数据检索