Image 1

Image 1


Image 2

enter image description here


Image 3

enter image description here

  1. 1st image is the settings screen and everything behaves normally upon the first loading of this screen.
  2. 2nd image is the policy screen which is pushed from the settings screen.
  3. 3rd image upon returning from the policy screen back to the settings screen shows the UI Slider now doesn't show the track image. The behavior still works normally, but the track is just gone. It's a very mysterious bug to me. If I go to another screen in the app and then hit settings it works fine again, but when I come from the policy screen the track image is gone.

I am using the default UISlider. I am using xib files for the different screens.

When the Policy Button is clicked...

EditorialPolicyViewController *policyView;
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
{
    policyView = [[EditorialPolicyViewController alloc]initWithNibName:@"EditorialPolicyViewController_iPad" bundle:nil];
}
else
{
    policyView = [[EditorialPolicyViewController alloc]initWithNibName:@"EditorialPolicyViewController_iPhone" bundle:nil];
}
[self.navigationController pushViewController:policyView animated:YES];

ViewDidLoad - setting up the uislider

NSString *textSize = [[NSUserDefaults standardUserDefaults] valueForKey:@"Text Size"];
float textSizeFloat = [textSize floatValue];
self.textSizeSlider.value = textSizeFloat;

[self.textSizeSlider setMaximumValue:16.0];
[self.textSizeSlider setMinimumValue:11.0];

Let me know if you have any other questions. I am out of ideas on how to solve this bug.

UPDATE Found that the code below was "theming" the slider but when I removed it, it worked fine. What is a way i can keep the theme color and not get it to disappear?

   [[UISlider appearance] setThumbTintColor:[UIColor colorWithRed:0/255.0f green:75/255.0f blue:152/255.0f alpha:1.0f]];
   [[UISlider appearance] setMinimumTrackTintColor:[UIColor colorWithRed:164/255.0f green:75.0f blue:25/255.0f alpha:1.0f]];
   [[UISlider appearance] setMaximumTrackTintColor:[UIColor colorWithRed:204/255.0f green:204/255.0f blue:204/255.0f alpha:1.0f]];
有帮助吗?

解决方案

This is the well known bug in SetMaximumTrackTintColor. Remove this line:

[[UISlider appearance] setMaximumTrackTintColor:[UIColor colorWithRed:204/255.0f green:204/255.0f blue:204/255.0f alpha:1.0f]]; 

and your app will work fine.

其他提示

It is correct that this is a known bug. But have found a way to work around it so that you can still keep your theming:

[[UISlider appearance] setMaximumTrackTintColor:[UIColor colorWithRed:204/255.0f green:204/255.0f blue:204/255.0f alpha:1.0f]];

In UIViewController's where I use a slider, I set the maximumTrackTintColor in the viewDidLoad: method

- (void)viewDidLoad
{
    [super viewDidLoad];
    _slider.maximumTrackTintColor = [UISlider appearance].maximumTrackTintColor;
}

This works for me, so I wanted to share!

you can move the appearance changes into the viewDidLoad: function. this way the appearance changes will only happened once.

- (void)viewDidLoad
{
    // Appearance changes here
}

it works for me

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top