Question

I have added a UISegmentedControl in the application. The segment control works fine and all i am doing with it is to get its selected state when a value is changes nothing else.

The UISegmentedControl initially looks like this

-

enter image description here

After i show an Reachability Not available state it looks like this

-

enter image description here

But after the application resumes and internet is connected and application resigns active it looks like this

enter image description here The UISegmentedControl does work properly but the color does not resume its state.
- The Reachibility blocks are in Application Delegates and have nothing to do with the UISegmentControl

EDIT

I have also checked that even after i set the color programatically in viewDidLoad or viewDidAppear or even in the state changed setting the TintColor of the UISegmentedControl it insted of an RGBA value it gives color as ( UIDeviceWhiteColorSpace 0.3 0.8 )

Was it helpful?

Solution

I had a similar problem.. This helped me You can give it a try

self.segControl.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;

this kind of acts like a refresh (what i call it) for the segment control

I had placed this in -(void)viewWillAppear:(BOOL)animated . You can place it in the same method or a method where the control would return after the networking call and alert is dismissed.

Hope this helps.

OTHER TIPS

Use break points to find the solution and then check whether the alpha colour has changed before and after internet connection. Or better you set tint appearance something like this..

#pragma mark - Appearance Methods

-(void)customizeAppearance {
UIColor *appTintColor = [UIColor colorWithRed:20/255.0f green:160/255.0f blue:160/255.0f 
alpha:1.0f];
[[UISearchBar appearance] setBarTintColor:appTintColor];
[[UISegmentedControl appearance] setTintColor:appTintColor];

self.window.tintColor = [UIColor colorWithRed:10/255.0f green:80/255.0f blue:80/255.0f 
alpha:1.0f];
}

I have got the same situation in my app.

I tried all the appearance methods but nothing seems to work. Instead it is all about showing the alertview at the right place. The alertview when shown causes the os to set the tintcolor to gray to the all items in the current viewcontroller. If when shown on viewcontroller launch there will be a conflict on which viewcontroller the tintcolor is changed. I guess this is causing the color change bug.

I guess you would have checked the reachability in you viewwillappear and you would have shown the alertview in the viewwillappear method. Instead have a bool value and set is as YES or NO depending on the values and then show the alertview of the internetconnection on viewdidappear by checking the bool value.

This is how i solved mine.

Instead of setting the color on interface builder try setting it programatically for the component.

Doing it this way will allow to to use breakpoints to check exactly what is happening after the Reachability notification is done.

You can simply call it on the constructor, for example:

[UIColor colorWithRed:66.0f/255.0f green:79.0f/255.0f blue:91.0f/255.0f alpha:1.0f]
[[UISegmentedControl appearance] setTintColor:appTintColor];

Perhaps you could re-confirm all tintsettings programmatically in the reachability's notification receiver?

-(void)reachabilityChanged:(NSNotification*)note 
{
 Reachability * reach = [note object];
  //set tints and colors either way (isReachable and !isReachable)
}

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(reachabilityChanged:)
                                             name:kReachabilityChangedNotification
                                           object:nil];

Remember that UIView in iOS 7 has a tintAdjustmentMode property.

In your case, this property has probably been set on your UISegmentedControl to UIViewTintAdjustmentModeDimmed when the screen was dimmed.

From the documentation of UIView:

If the view’s tintAdjustmentMode property’s value is UIViewTintAdjustmentModeDimmed, then the tintColor property value is automatically dimmed.

You must set the divider image whose height and width should be same as the height of segment control, divided into two halves red and blue in your case

use the following code:

[segmentControllerObj setDividerImage:[UIImage imageNamed:@"left.png"] forLeftSegmentState:UIControlStateSelected rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[segmentControllerObj setDividerImage:[UIImage imageNamed:@"right.png"] forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top