自定义UITableViewCell,带有居中的UISlider和两个图像 [英] Custom UITableViewCell with centered UISlider and two images
问题描述
我想以编程方式使用 UISlider
创建自定义 UITableViewCell
两端的中心和两个图像。有关示例,请参阅任何iOS设备上的亮度设置。它的中央有一个UISlider,两端有两个类似太阳的图像(一个小,一个大)。这基本上就是我所说的:
I'd like to programmatically create a custom UITableViewCell
with a UISlider
in the center and two images at either end. For an example see the Brightness setting on any iOS device. It has a UISlider in the center and two sun-like images at either end (one small and one large). Here's basically what I'm talking about:
以编程方式创建此自定义 UITableViewCell
的最简单方法是什么?
What's the easiest way to programmatically create this custom UITableViewCell
?
干杯!
推荐答案
添加图片的最简单方法UISlider的任何一端都是使用 setMinimumTrackImage:forState:
和 setMaximumTrackImage:forState:
。
The easiest way to add the images at either end of a UISlider is to use setMinimumTrackImage:forState:
and setMaximumTrackImage:forState:
.
要将UISlider添加到UITableViewCell,只需将其添加为单元格的 contentView
的子视图,并设置滑块的 frame
(或 bounds
和 center
)和 autoresizingMask
视情况而定。
To add a UISlider to a UITableViewCell, just add it as a subview of the cell's contentView
, and set the slider's frame
(or bounds
and center
) and autoresizingMask
as appropriate.
[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;
忽略单元格的 imageView
, textLabel
, detailTextLabel
properties;如果您从未访问过这些属性,则单元格可能甚至无法创建相应的视图。
Ignore the cell's imageView
, textLabel
, and detailTextLabel
properties; if you never access these properties, the cell may not even bother to create the corresponding views.
这篇关于自定义UITableViewCell,带有居中的UISlider和两个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!