Nik's
Nik's

Reputation: 690

how to customised slider?

I have Created my customized slider like this

UIImage *image = [UIImage imageNamed:@"thumb.png"];


CGRect frame = CGRectMake(22.5, 220.0, 280.0, 20.0);
UISlider *myslider = [[UISlider alloc] initWithFrame:frame];


[myslider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged];
[myslider setBackgroundColor:[UIColor clearColor]];

[myslider setThumbImage:image  forState:UIControlStateNormal];
UIImage *stetchLeftTrack = [[UIImage imageNamed:@"leftLineImage.png"]
                            stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
UIImage *stetchRightTrack = [[UIImage imageNamed:@"SlideRight.png"]
                             stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];

[myslider setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
[myslider setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];


 myslider.minimumValue = 0.0;
 myslider.maximumValue = 100.0;
 myslider.continuous = YES;
 myslider.value = 5.0;
[self.view addSubview:myslider];

In this slider i have taken slider left track image and slider right track image the size of both images are same i have done this by adjust size of preview but still I am getting my left track image is bigger how can I solve this problem. and my second question i have call the event on slider value change but i need to call a event when the slider get slide-fully or slider value get 100 how can I do this also.

Upvotes: 1

Views: 349

Answers (1)

Gypsa
Gypsa

Reputation: 11314

Hi for your first question refer UICatalog app example provided in developer.

http://developer.apple.com/library/ios/#samplecode/UICatalog/Introduction/Intro.html

For second answer you can try this:-

- (void)sliderChanged:(id)sender
{
if (sender.value==100) {
//do your code  
}
    else {
        //do nothing
    }

}

Upvotes: 1

Related Questions