9

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 )

7 Answers7

19

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.

Prathamesh Saraf
  • 709
  • 4
  • 14
3

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];
}
MarkP
  • 2,546
  • 5
  • 31
  • 48
Chan
  • 447
  • 1
  • 5
  • 18
  • How i could use breakpoints if i am setting the tint color from Interface Builder? –  May 14 '14 at 11:47
  • Better set it as given in the above mentioned method or else on viewWillAppear or viewDidAppear method set the tint colour of the UISegmentControl. – Chan May 14 '14 at 11:56
  • In some cases the color fades away even when the application isn't in the background. Any way the appearance could be set Globally in the Reachability Block? –  May 14 '14 at 12:00
  • I'm also using this type in one of my program. I have set the tint colour in viewDidLoad method like this. Just try to add this code without setting the colour on interface builder. [segmentedControl setTintColor:[UIColor colorWithRed:35.0f/255 green:84.0f/255 blue:136.0f/255 alpha:1]]; – Chan May 14 '14 at 12:15
  • 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 ) –  May 14 '14 at 12:38
1

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.

ipraba
  • 16,485
  • 4
  • 59
  • 58
  • I have reachabillity blocks in my Application Delegate and the AlertView is added to the window.. The Alertview is dismissed when while the view is not shown when application enters foreground. Thus unable to set the proper tint color. –  May 19 '14 at 10:15
0

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];
Jose Luis
  • 3,307
  • 3
  • 36
  • 53
0

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];
BossBols
  • 175
  • 12
0

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];
Pawan Rai
  • 3,434
  • 4
  • 32
  • 42
nutz
  • 212
  • 1
  • 4
0

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.

augustzf
  • 2,385
  • 1
  • 16
  • 22