簡體   English   中英

使用xcode 5界面構建器設置選項卡欄色調(背景)顏色

[英]using xcode 5 interface builder for setting tab bar tint (background) color

我對ios開發很陌生,我有以下問題。 在xcode 5的情節提要中設計tabBar時,我意識到我無法為ios 6設置tabBar的背景色。

這似乎與以下事實有關:在ios6中,bar backgroundcolor為tintColor,而在ios 7中,其變為了barTintColor。

如果將情節提要的“查看方式”參數更改為“ iOS 6.1和Ealier”,則會看到背景顏色從我在屬性編輯器(Bar Tint)中設置的正確值更改為iOS 6的標准值。

當然,我可以從代碼中設置值,但這對可維護性不利。

有什么辦法可以在xcode 5接口構建器中為iOS 6定義此值?

更新:由於到目前為止,我還沒有找到令人滿意的解決方案,因此我使用以下解決方法。 我在屬性檢查器中將tabBar的背景色設置為視圖中的屬性“ Bar Tint”和“ Background”。 在我的應用程序委托中,我使用以下代碼:

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;

if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7) {
    [tabBar setSelectedImageTintColor:tabBar.tintColor];
    tabBar.tintColor = tabBar.backgroundColor;
}

我遇到了同樣的問題。 不幸的是,您將必須使用類似於以下內容的代碼來保留iOS 6的兼容性:

// iOS 6 compatibility
NSString *reqSysVer = @"7.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];

if ([currSysVer compare:reqSysVer options:NSNumericSearch] == NSOrderedAscending) {
    [[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:66.f/255.f green:173.f/255.f blue:179.f/255.f alpha:1.f]];
    [[UIBarButtonItem appearance] setTintColor:[UIColor colorWithRed:66.f/255.f green:173.f/255.f blue:179.f/255.f alpha:1.f]];
}

我不確定InterfaceBuilder中的'tint'為什么不起作用,但這不是我們的目的。

注意:如果要支持iOS <5.0,則必須修改iOS版本檢查,因為UIAppearance協議僅在iOS 5.0之后可用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM