【问题标题】:indent grouped cells like iphone contacts缩进分组单元格,如 iphone 联系人
【发布时间】:2012-12-02 23:51:19
【问题描述】:

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

类似这样的:screeshot

我该怎么做?

谢谢, 最大

【问题讨论】:

    标签: iphone uitableview


    【解决方案1】:

    其他解决方案要求您创建自己的背景图像并使用两个不方便的表格视图。我所做的是子类 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(例如,在故事板单元原型上),您应该会获得与联系人应用中的“添加联系人”视图相同的效果。

    【讨论】:

    • 我仍然看到缩进单元格左侧的分隔线,但后来意识到它在 UITableView 中:[tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    【解决方案2】:

    请看这个问题:

    Is it possible to adjust the width of a UITableViewCell?

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

    【讨论】:

      【解决方案3】:

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

      (1) 具有与 UITableViewStyleGrouped 背景颜色相似的视图的父视图控制器。

      (2) 在作为子视图的 UIImageView 上添加照片到 (1)

      (3)将右侧的UITableView(Grouped Style)作为子视图再次添加到(1)

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

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

      【讨论】:

      • 这并没有达到他想要的效果——他希望后面的表格部分是全宽的。
      • 我曾经需要两个子视图相互同步滚动。左和右。您也可以通过委托轻松实现这一目标。 SO上有很多帖子对此进行了描述。
      • 不敢相信没有一种简单的方法可以调用缩进,即使您不处于编辑模式。无论如何....我知道方法,很多工作要做子类化世界;)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-17
      • 2017-09-07
      • 1970-01-01
      • 1970-01-01
      • 2011-03-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多