2016-07-18 28 views
0

正如在主題中,我想知道現在在React Native中是否可以將非活動TabBar圖標的顏色從默認灰色更改爲自定義顏色?無論是否使用react-native-vector-icons是否可以在React Native中更改不活動的TabBarIOS圖標顏色?

+0

爲什麼不試試,看看自己? –

+0

我試過了,但是我找不到解決方案,我嘗試了造型,圖標源自自定義顏色的react-native-vector-icons,但它不起作用,灰色覆蓋了我的自定義顏色。所以我決定問。 – enterteg

回答

0

我找到了解決方案,但是您的圖標應該處於「無效」顏色。爲了實現這一目標去RTCTabBarItem.m並更改第一行方法setIcon

- (void)setIcon:(UIImage *)icon 
{ 
    _icon = [icon imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 
    if (_icon && _systemIcon != NSNotFound) { 
    _systemIcon = NSNotFound; 
    UITabBarItem *oldItem = _barItem; 
    _barItem = [UITabBarItem new]; 
    _barItem.title = oldItem.title; 
    _barItem.imageInsets = oldItem.imageInsets; 
    _barItem.selectedImage = oldItem.selectedImage; 
    _barItem.badgeValue = oldItem.badgeValue; 
    } 
    self.barItem.image = _icon; 
} 

然後在所有TabBarIOS.Item用相同的URL添加場selectedIconicon(也就是不管),TabBarIOS的設置tintColor爲「活動「顏色,就這些! TabBar將以默認圖標顏色(不活動)呈現,活動圖標將在tintColor中。我認爲TabBar字段renderAsOriginal應該這樣做,但它不起作用。畢竟,我發現在GitHub上該解決方案https://github.com/facebook/react-native/issues/3083


另一種解決方案(可能無法在某些情況下工作):

  1. 在Xcode中查找文件RCTTabBar.mcmd + shift + f
  2. 找到- (instancetype)initWithFrame:(CGRect)frame
  3. 在此之前加入return self
 
[[UIView appearanceWhenContainedIn: [UITabBar class], nil] setTintColor: [UIColor redColor]]; 
[[UITabBar appearance] setSelectedImageTintColor: [UIColor greenColor]]; 
  • 重新啓動模擬器/設備
  • 在代碼redColor處於非活動狀態的按鈕的顏色,和greenColor是活性按鈕顏色。有關詳細信息結帳這個Unselected UITabBar color?

    編輯:我發現偉大的工具,如果你想轉換RGB到的UIColor http://uicolor.xyz/

    相關問題