【问题标题】:Custom UITableViewCell with centered UISlider and two images具有居中 UISlider 和两个图像的自定义 UITableViewCell
【发布时间】:2011-07-31 04:25:52
【问题描述】:

我想以编程方式创建一个自定义 UITableViewCell,其中一个 UISlider 在中心,两个图像在两端。有关示例,请参阅任何 iOS 设备上的亮度设置。它的中心有一个 UISlider,两端有两个类似太阳的图像(一个小,一个大)。这基本上就是我要说的:

以编程方式创建此自定义 UITableViewCell 的最简单方法是什么?

干杯!

【问题讨论】:

    标签: ios uitableview uislider


    【解决方案1】:

    在 UISlider 的任一端添加图像的最简单方法是使用 setMinimumTrackImage:forState:setMaximumTrackImage:forState:

    要将 UISlider 添加到 UITableViewCell,只需将其添加为单元格的contentView 的子视图,并根据需要设置滑块的frame(或boundscenter)和autoresizingMask

        [cell.contentView addSubview:slider];
        slider.bounds = CGRectMake(0, 0, cell.contentView.bounds.size.width - 10, slider.bounds.size.height);
        slider.center = CGPointMake(CGRectGetMidX(cell.contentView.bounds), CGRectGetMidY(cell.contentView.bounds));
        slider.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
    

    忽略单元格的imageViewtextLabeldetailTextLabel属性;如果您从不访问这些属性,则单元格甚至可能不会费心创建相应的视图。

    【讨论】:

    • 不错的一个。我在第一行修复了一个编译时错误,请建议slider.center = cell.contentView.center;
    【解决方案2】:

    您必须将UITableViewCell 子类化,然后将UISlider 子类添加到单元格内容视图。最后,您必须在 UISlider 上覆盖它:

    -drawRect() 
    

    要包含这 2 张图片。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-13
      相关资源
      最近更新 更多