UISlider track image disappears when returning from a specific view

Image 1

Image 1


Image 2

enter image description here


Image 3

enter image description here

  • The 1st image is the settings screen, and everything behaves normally when you first load this screen.
  • The second image is a policy screen that is popped from the settings screen.
  • The third image after returning from the policy screen back to the settings screen shows that the user interface of the slider now does not show the image of the track. The behavior is still working fine, but the track has just disappeared. This is a very mysterious mistake for me. If I switch to another screen in the application and then delete the settings, it works fine again, but when I exit the policy screen, the image of the track will disappear.

I use UISlider by default. I use xib files for different screens.

""...

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 - 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];

, . , .

UPDATE , "" , , . ?

   [[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]];
+4
3

SetMaximumTrackTintColor. :

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

.

+4

viewDidLoad:. .

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

0

, . , :

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

In the UIViewController, where I use the slider, I set maxTrackTintColor in the viewDidLoad method:

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

This works for me, so I wanted to share!

0
source

Source: https://habr.com/ru/post/1537925/


All Articles