Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISlider setMaximumTrackTintColor in iOS 7.1

Tags:

ios

uislider

[slider setMaximumTrackTintColor: color]

has unexpected results in iOS 7.1 (the slider bar changes its position appearing at top instead of vertical center or disappears completely), while working fine with prior versions.

[slider setMinimumTrackTintColor: color]

does render the expected result.

This question might be related: UISlider setMaximumTrackTintColor, but no answer so far.

Update:

I get this: wrong instead of: enter image description here

Update #2:

Using setMaximumTrackImage might work, but the solution I'm looking for is a way to set any random color and not a preexisting image.

Update #3:

This issue is still present in iOS 7.1.1.

like image 776
user623396 Avatar asked Mar 12 '14 08:03

user623396


1 Answers

Found this workaroud:

Create a 1x1px UIImage from a UIColor on the fly:

CGRect rect = CGRectMake(0, 0, 1, 1);
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
[color setFill];
UIRectFill(rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

and then

[slider setMaximumTrackImage:image forState:UIControlStateNormal];

Looks like an expensive solution but it gets the job done.

like image 184
user623396 Avatar answered Oct 05 '22 06:10

user623396