簡體   English   中英

在UITabBar中為選定的選項卡設置色調顏色

[英]setting tint color for selected tab in UITabBar

在Xcode 5 Dev Preview 2中,我能夠執行以下操作:

[[UITabBar appearance] setTintColor:[UIColor whiteColor]]; //所選圖像和文字的顏色(白色)

在Xcode 5 Dev Preview 3中,同一行代碼拋出異常(見下文)。 異常表明我可能想要使用' barTintColor ' - 但我沒有 - 因為這是整個UITabBar的顏色。 如何在UITabBar中設置所選圖像和文本的顏色?

Xcode 5 Dev Preview 3中的新例外:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-setTintColor: is not allowed for use with the appearance proxy. Perhaps you want to use the barTintColor property.'

謝謝

我沒有看到最新的Xcode 5(5.0.2),但我知道你想調用不同的方法設置所選的圖像色調顏色取決於你是在iOS 6或7上運行。這里有一些來自我的某個應用的示例代碼:

if ([RFSUtilities isIOS7OrHigher])
{
    [[UITabBar appearance] setTintColor:[UIColor whiteColor]];
}
else
{
    [[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];
}

+[RFSUtilities isIOS7OrHigher]只是通過正確的版本檢查來檢查我們是否在iOS 7或更高版本上運行

+ (BOOL)isIOS7OrHigher
{
    float versionNumber = floor(NSFoundationVersionNumber);
    return versionNumber > NSFoundationVersionNumber_iOS_6_1;
}

希望這可以幫助!

只需在UITabBar類的User Defined Runtime Attribute中添加顏色類型的tintColor

仍然在尋找非活動標簽的類似方法......任何人都知道嗎?

暫無
暫無

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

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