0

When using Apple's UISplitViewController, the master view has a black toolbar when in portrait mode and gray when in landscape.

I have created a label inside a UIView on the toolbar, as described here: Adding a UILabel to a UIToolbar, but by default the text is black which means it is only visible in landscape mode.

How should I code my view controller so it can change the text color so it is always visible, and ideally to match the way Apple apps like Mail work (white in portrait and dark gray in landscape) ?


...later...

Following the direction in Alan Moore's answer, I decided to use code like this:

UIInterfaceOrientation o = [UIApplication sharedApplication].statusBarOrientation;
if (UIDeviceOrientationIsPortrait(o)) 
    label.textColor = [UIColor whiteColor];
else
    label.textColor = [UIColor darkTextColor];

This is called from my viewDidLoad and didRotateFromInterfaceOrientation methods. Seems to me that didRotate is better than shouldRotate for this case.

Also note I am querying the statusBar, because in my view self.interfaceOrientation always returns 1. This is also noted here: Determine UIInterfaceOrientation on iPad.

Not 100% sure that darkText is the right color for landscape.

Community
  • 1
  • 1
Bryan
  • 11,398
  • 3
  • 53
  • 78
  • If you can provide some sample code, it would be easier to suggest changes. – Alan Moore Oct 02 '11 at 21:03
  • Sorry, the code is in the item I linked to, in the answer currently at 41 votes. Actually I used the Interface Builder method in the answer from 'Matt R', but it works out the same. – Bryan Oct 02 '11 at 21:07

1 Answers1

0

I would add code to the

- (BOOL)shouldAutorotateToInterfaceOrientation:(...) {
}

which would do a setTextColor on your label depending on whether it's rotating to portrait or landscape mode.

Alan Moore
  • 6,525
  • 6
  • 55
  • 68
  • Hmm. What about the cases where it is being shown for the first time? Empirically shouldAutorotate does get called after viewDidLoad, but is that guaranteed? – Bryan Oct 02 '11 at 21:23
  • Guaranteed? Well I haven't seen any Apple document that says its guaranteed, but I think it has to call this in order to determine how to draw the view. – Alan Moore Oct 02 '11 at 21:29
  • The UIViewController documentation does describe what is supposed to happen: At launch time, applications should always set up their interface in a portrait orientation. After the application:didFinishLaunchingWithOptions: method returns, the application uses the view controller rotation mechanism described above to rotate the views to the appropriate orientation prior to showing the window. – Bryan Oct 02 '11 at 22:12
  • I accepted your answer, since you helped get me thinking along the right lines. Thanks! – Bryan Oct 02 '11 at 23:00