缩进分组的单元格,如iphone联系人

时间:2011-03-04 15:50:40

标签: iphone uitableview

我想要一个分组表,其中第一部分有2行和1个图像视图,如联系人应用。

类似这样的事:screeshot

我该怎么做?

谢谢, 最大

3 个答案:

答案 0 :(得分:3)

其他解决方案要求您创建自己的背景图像并使用两个不方便的tableview。我所做的是子类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 :(得分:1)

请看这个问题:

Is it possible to adjust the width of a UITableViewCell?

似乎没有方便的方法来实际减少单元格(或单元格组)的宽度。

答案 2 :(得分:0)

您可以通过以下方式在屏幕截图中实现相同的目标:

(1)父视图控制器,其视图的背景颜色类似于UITableViewStyleGrouped的背景颜色。

(2)将照片添加到UIImageView上,该视图是(1)

的子视图

(3)再次将右侧的UITableView(分组样式)作为子视图添加到(1)

正确设置两个子视图的帧,并相应地设置屏幕截图中的布局,并使用委托“逻辑连接”两个子视图。

编辑:可以使用[UIColor colorWithPatternImage:(UIImage *)image]实现背景颜色。只需从iphone模拟器上的任何示例应用程序中裁剪背景。

相关问题