ios - 如何制作单元格小于背景的表格 View Controller ?

标签 ios objective-c uitableview

我正在尝试制作一个表格 View Controller ,其中的单元格在所有边上都有很小的边距,并覆盖背景图像。我在 Google 上找到的教程没有涵盖为整个 View 制作背景和使单个单元格具有边距。

这是 Scoutmob 的一个粗略示例,说明我正在努力实现的目标:

One of Scoutmob's more recent design themes

最佳答案

最好的方法可能是在 layoutSubviews 中调整 UITableViewCell 的 contentViewbackgroundViewselectedBackgroundView 的大小>.

例如:

- (void)layoutSubviews {

    [super layoutSubviews];

    const CGRect insetRect            = CGRectInset( self.bounds, 10, 10 );

    self.contentView.frame            = insetRect;
    self.backgroundView.frame         = insetRect;
    self.selectedBackgroundView.frame = insetRect;
}

如果您想使用图像背景,请将 backgroundView 设置为 UIImageView。

使用此方法允许您支持旋转,以及重新排序和删除控件以及 UITableView 对其单元格执行的所有其他操作(不要忘记将 subview 添加到单元格的 contentView 和不直接到它的 View )。

关于ios - 如何制作单元格小于背景的表格 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16756084/

相关文章:

ios - 如何更改表格 View 单元格文本?

iphone - Xcode for iPhone 静态库和动态库的区别

ios - 如何从另一个 uitableviewcell 中的 tableview 导航?

ios - 使用 UIStackView 时 UIImageView 被挤压到 UITableViewCell 内

ios - 设置 UIScrollView 的边界

c - mac屏保启动事件

objective-c - JSON 字典中的无效(非字符串)键

ios - SwiftUI - 使用 Toggle 隐藏列表项

ios - 状态恢复时 Root View Controller 显示短暂

ios - 使用 NSLayoutContraints 添加第二个 subview Controller ,始终将其放置在导航栏下方,而不是导航栏之后