简体   繁体   中英

How to place image on UISlider?

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?

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.

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM