當前位置:編程學習大全網 - 站長素材 - 如何更改為iOS的7 tabBarItems文本和圖標的顏色

如何更改為iOS的7 tabBarItems文本和圖標的顏色

1. 有兩件事情妳需要做的是: 1)如果妳想自定義的TabBar本身,妳需要設置barTintColor為tabBarController: // this will generate a black tab bar

tabBarController.tabBar.barTintColor = [UIColor blackColor];

// this will give selected icons and text your apps tint color

tabBarController.tabBar.tintColor = appTintColor; // appTintColor is a UIColor *

2)設置tabBarItem文本外觀要覆蓋每壹個狀態:[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f],

NSForegroundColorAttributeName : appTintColor

} forState:UIControlStateSelected];

// doing this results in an easier to read unselected state then the default iOS 7 one

[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f],

NSForegroundColorAttributeName : [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:1]

} forState:UIControlStateNormal];

2. 這個工作要在著色的標簽欄不活躍的項目UITabBarItem *item = [self.tabBar.items objectAtIndex:1];

//這裏妳需要用妳想要的顏色的圖標,因為它會被渲染,因為它是item.image = [[UIImage imageNamed:@"unselected.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

//這個圖標選中的標簽,它會得到有色定義見self.tabBar.tintColor

item.selectedImage = [UIImage imageNamed:@"selected.png"];

3. 使用self.tabBarController.tabBar.barStyle = UIBarStyleBlack;使標簽欄黑色

4. 埃德的答案是完美的,但補充壹點。 的TabBar是默認的半透明使用TabBar下受到的觀點的顏色(即的ViewController的視圖的顏色影響的TabBar外觀)。 所以我設置下面的代碼不會受到影響。self.tabBarController.tabBar.translucent = false;

連同Ed的這裏的答案是代碼了。self.tabBarController.tabBar.barTintColor = [UIColor blackColor];

self.tabBarController.tabBar.translucent = false;

self.tabBarController.tabBar.tintColor = [UIColor blueColor];

5. 妳試試吧for (UITabBarItem *item in self.tabBarController.tabBar.items) {

item.image = [[UIImage imageNamed:@"youimage.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:

[UIColor whiteColor], UITextAttributeTextColor,

nil] forState:UIControlStateNormal];

item.selectedImage = [UIImage imageNamed:@"youimage.png"];

}

  • 上一篇:挖料就好。
  • 下一篇:長沙是壹座怎樣的城市?
  • copyright 2024編程學習大全網