如何更改标签文本以与UISplitView中的工具栏背景颜色形成对比?

时间:2011-10-02 20:53:28

标签: ios ipad uisplitviewcontroller

使用Apple的UISplitViewController时,主视图在纵向模式下有黑色工具栏,在横向模式下有灰色。

我在工具栏上的UIView中创建了一个标签,如下所述:Adding a UILabel to a UIToolbar,但默认情况下文本为黑色,这意味着它只能在横向模式下显示。

我应该如何对视图控制器进行编码,以便它可以更改文本颜色以使其始终可见,并且理想情况下与Apple应用程序(如邮件)的工作方式相匹配(纵向为白色,横向为深灰色)?

<小时/> ...后...

按照Alan Moore的回答,我决定使用这样的代码:

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

这是从我的viewDidLoad和didRotateFromInterfaceOrientation方法中调用的。在我看来,对于这种情况,didRotate比shouldRotate更好。

另请注意,我正在查询statusBar,因为在我看来,self.interfaceOrientation始终返回1.此处还会注明:Determine UIInterfaceOrientation on iPad

不是100%确定darkText是适合风景的颜色。

1 个答案:

答案 0 :(得分:0)

我会将代码添加到

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

会在你的标签上做一个setTextColor,具体取决于它是旋转到纵向模式还是横向模式。