I have a UISlider
that I want to put a custom created UIImage
on to be stretched. I create it like this:
UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width * difference, image.size.height)];
iv.backgroundColor = [BSFunctions getColorFromHex:@"f7f8fa"];
iv.image = cappedImage;
[self addSubview:iv];
UIGraphicsBeginImageContextWithOptions (iv.frame.size, YES, [[UIScreen mainScreen] scale]);
[iv.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[iv removeFromSuperview];
return img;
I can confirm that the image is created right and it looks like this:
However, when I put it to a slider and the image starts to stretch, it looks like this:
The way I add it to the slider is the following:
UIImage *newImage = [self imageStretchedOnLeft];
UIImage *rightStretchImage = [newImage resizableImageWithCapInsets:UIEdgeInsetsMake(0, newImage.size.width - 2, 0, 0)];
[self setMinimumTrackImage:rightStretchImage forState:UIControlStateNormal];
It used to be working a couple of builds ago and I was not touching anything when it suddenly stopped to work. What's even more surprising, UISlider
works like it should on iOS 5.1 simulator and therefore on iOS 5! This whole thing is driving me crazy and I don't know how to even approach it. Any help would be appreciated.
I'm creating an app for iOS 5 and up and testing it on iOS 6
Solved the problem like this:
if (iosVersion < 6.0){
rightStretchImage = [newImage resizableImageWithCapInsets:UIEdgeInsetsMake(0, newImage.size.width - 2, 0, 0)];
}else{
rightStretchImage = [newImage resizableImageWithCapInsets:UIEdgeInsetsMake(0, newImage.size.width - 2, 0, 0) resizingMode:UIImageResizingModeStretch];
}