【发布时间】:2012-12-02 23:51:19
【问题描述】:
【问题讨论】:
标签: iphone uitableview
【问题讨论】:
标签: iphone uitableview
其他解决方案要求您创建自己的背景图像并使用两个不方便的表格视图。我所做的是子类 UITableViewCell 并将背景视图缩进如下:
#define INDENT_WIDTH 84
...
- (void)layoutSubviews
{
[super layoutSubviews];
//Indent the background views.
CGRect frame = self.backgroundView.frame;
frame.origin.x = frame.origin.x + INDENT_WIDTH;
frame.size.width = frame.size.width - INDENT_WIDTH;
self.backgroundView.frame = frame;
self.selectedBackgroundView.frame = frame;
//Also indent the UIImageview that contains like a shadow image over the backgroundviews (in grouped tableview style only).
for (UIView *subview in self.subviews) {
if ([subview isKindOfClass:[UIImageView class]]) {
CGRect frame = subview.frame;
frame.origin.x = frame.origin.x + INDENT_WIDTH;
frame.size.width = frame.size.width - INDENT_WIDTH;
subview.frame = frame;
}
}
}
由于内容视图具有透明背景色,您可以在左侧放置一个 UIImageView(例如,在故事板单元原型上),您应该会获得与联系人应用中的“添加联系人”视图相同的效果。
【讨论】:
【讨论】:
您可以通过以下方式在屏幕截图中实现相同的效果:
(1) 具有与 UITableViewStyleGrouped 背景颜色相似的视图的父视图控制器。
(2) 在作为子视图的 UIImageView 上添加照片到 (1)
(3)将右侧的UITableView(Grouped Style)作为子视图再次添加到(1)
为屏幕截图中的布局正确并相应地设置两个子视图的框架,并使用委托来“逻辑连接”两个子视图。
编辑:背景颜色可以使用[UIColor colorWithPatternImage:(UIImage *)image]来实现。只需从 iphone 模拟器上的任何示例应用程序中裁剪背景。
【讨论】: