UISlider with ProgressView combined

后端 未结 9 1386
无人共我
无人共我 2020-11-29 16:07

Is there an apple-house-made way to get a UISlider with a ProgressView. This is used by many streaming applications e.g. native quicktimeplayer or youtube. (Just to be sure:

9条回答
  •  既然无缘
    2020-11-29 17:10

    This is doable using the standard controls.

    In Interface Builder place your UISlider immediately on top of your UIProgressView and make them the same size.

    On a UISlider the background horizontal line is called the track, the trick is to make it invisible. We do this with a transparent PNG and the UISlider methods setMinimumTrackImage:forState: and setMaximumTrackImage:forState:.

    In the viewDidLoad method of your view controller add:

    [self.slider setMinimumTrackImage:[UIImage imageNamed:@"transparent.png"] forState:UIControlStateNormal];
    [self.slider setMaximumTrackImage:[UIImage imageNamed:@"transparent.png"] forState:UIControlStateNormal];
    

    where self.slider refers to your UISlider.

    I've tested the code in Xcode, and this will give you a slider with an independent progress bar.

提交回复
热议问题