How to place image on UISlider?

2019-06-10 10:50发布

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

CAn any body help me?

2条回答
我想做一个坏孩纸
2楼-- · 2019-06-10 11:27

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;
}
查看更多
三岁会撩人
3楼-- · 2019-06-10 11:41

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.

查看更多
登录 后发表回答