How to place image on UISlider?

2019-06-10 10:35发布

问题:

I have to place a slider and want to place an imge on slider. the slider i want is this

CAn any body help me?

回答1:

See the UISlider class reference. You want to set setThumbImage:forState: as well as setMinimumTrackImage:forState: and setMaximumTrackImage:forState:. Use the same images for the minimum and maximum track images, and use UIControlStateNormal for the state.



回答2:

Below code will be in ViewWillAppear...

-(void)viewWillAppear:(BOOL)animated
{
    slider.backgroundColor = [UIColor clearColor];  
    UIImage *stetchLeftTrack = [[UIImage imageNamed:@"yellowslide.png"]
                                stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
    UIImage *stetchRightTrack = [[UIImage imageNamed:@"yellowslide.png"]
                                 stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
    [slider setThumbImage: [UIImage imageNamed:@"1.PNG"] forState:UIControlStateNormal];
    [slider setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
    [slider setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];
    slider.minimumValue = 1.0;
    slider.maximumValue = 3.0;
    slider.continuous = YES;
    slider.value = 0.0;
}