0

I am developing an application in iOS , and I have created a vertical UISlider by following code:

 UISlider *BrightnessSlider;
 BrightnessSlider = [[UISlider alloc] initWithFrame:CGRectMake(24, 132, 118, 34)];

 BrightnessSlider.minimumValue = 0;
 BrightnessSlider.maximumValue = 100;
 BrightnessSlider.value = (BrightnessSlider.minimumValue + BrightnessSlider.maximumValue) / 2;
 BrightnessSlider.continuous = YES;
 BrightnessSlider.transform =CGAffineTransformMakeRotation(M_PI*1.5);
 [BrightnessSlider addTarget:self action:@selector(BrightnessSliderValueChanged:) forControlEvents:UIControlEventValueChanged];

 [self.view addSubview:BrightnessSlider];

And tried to setting the background image of UISlider by using the following code:

 UIImage *clearImage = [[UIImage imageNamed:@"SliderBar.png"] stretchableImageWithLeftCapWidth:5.0 topCapHeight:0.0];
 [BrightnessSlider setMinimumTrackImage:clearImage forState:UIControlStateNormal];
 [BrightnessSlider setMaximumTrackImage:clearImage forState:UIControlStateNormal];

But the image is coming as horizontal , did I missing something ?

Thanks in advance.

-------------------------------EDIT--------------------------------------

The code is like the following:

UIGraphicsBeginImageContext(self.view.frame.size);
[[UIImage imageNamed:@"brightness_slider.png"] drawInRect:self.view.bounds];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextRotateCTM (context, radians(90));
UIImage *sliderimage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

[BrightnessSlider setMinimumTrackImage:sliderimage forState:UIControlStateNormal];
[BrightnessSlider setMaximumTrackImage:sliderimage forState:UIControlStateNormal];

The image of UISlider is like the following picture; enter image description here

Wun
  • 6,211
  • 11
  • 56
  • 101

0 Answers0