Custom UITableViewCell with centered UISlider and two images

≯℡__Kan透↙ 提交于 2019-12-01 07:35:11
Anomie

The easiest way to add the images at either end of a UISlider is to use setMinimumTrackImage:forState: and setMaximumTrackImage:forState:.

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;

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.

You will have to subclass UITableViewCell, then add a UISlider subclass to the cells contentView. Finally you will have to override this on the UISlider:

-drawRect() 

To include those 2 images.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!