【发布时间】:2011-10-03 06:21:15
【问题描述】:
使用 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 是横向的正确颜色。
【问题讨论】:
-
如果您可以提供一些示例代码,建议更改会更容易。
-
对不起,代码在我链接到的项目中,目前有 41 票。实际上,我在“Matt R”的答案中使用了 Interface Builder 方法,但效果相同。
标签: ios ipad uisplitviewcontroller