Set the color of the tabBar image, height, and title,
Implemented the following content:
1. Set the selected and unselected tabBarItem images. The images are full of items;
2. The height of tabBar is adjusted;
3. changed the title Color and position.
------------ The code is as follows:
--- TabBarC. m ---
# Import "TabBarC. h"
# Import "ViewController. h"
# Import "SecViewController. h"
# Define CustomTabBarHeight 60 // you do not need to change the height to self. tabBar. frame. size. height.
# Define CustomTabBarWidth self. tabBar. frame. size. width
@ Interface TabBarC ()
@ End
@ Implementation TabBarC
-(Void) viewDidLoad {
[Super viewDidLoad];
// Initialize the sub-Controller
ViewController * onevc = [[ViewController alloc] init];
SecViewController * twovc = [[SecViewController alloc] init];
// Place the VC, unselected Image Library, and the selected image into the array.
NSArray * onevcArr = @ [onevc, @ "one_icon", @ "sel_one_icon"];
NSArray * twovcArr = @ [twovc, @ "two_icon", @ "sel_two_icon"];
NSArray * vcArr = @ [onevcArr, twovcArr];
[Self addToTabBar: vcArr];
}
// Add the sub-controller to the tabBar
-(Void) addToTabBar :( NSArray *) array {
For (NSInteger I = 0; I <array. count; I ++ ){
NSArray * everyVCArr = array [I];
UIViewController * everyVC = everyVCArr [0];
EveryVC. title = @ "vc title ";
EveryVC. view. backgroundColor = [UIColor whiteColor];
// Move the inserted image 5.5 down. When the top and bottom are not the opposite, the image changes.
EveryVC. tabBarItem. imageInsets = UIEdgeInsetsMake (5.5, 0,-5.5, 0 );
// Width of tabBarItem
NSInteger itemWidth = CustomTabBarWidth/array. count;
# Pragma ------- Note: (if tabBarItem. image is not set, other tabBarItem settings are invalid)
# Pragma ------- no suitable images of different sizes are prepared here. To show the effect, scale the image to the appropriate size. The scaling steps can be omitted.
// -------- Set the image when it is not selected, and set the image to the original state
EveryVC. tabBarItem. image = [[self editImage: everyVCArr [1] toSize: CGSizeMake (itemWidth, CustomTabBarHeight)] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
// Set the selected image. The image is set to the original state.
EveryVC. tabBarItem. selectedImage = [[self editImage: everyVCArr [2] toSize: CGSizeMake (itemWidth, CustomTabBarHeight)] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
// Adjust the title Position of tabBarItem
[EveryVC. tabBarItem setTitlePositionAdjustment: UIOffsetMake (0, 5)];
// Set the font color
NSMutableDictionary * textAttribute = [NSMutableDictionary dictionary];
TextAttribute [NSForegroundColorAttributeName] = [UIColor blackColor];
[EveryVC. tabBarItem setTitleTextAttributes: textAttribute forState: UIControlStateNormal];
// Set the font color
[EveryVC. tabBarItem setTitleTextAttributes: @ {NSForegroundColorAttributeName: [UIColor redColor]} forState: UIControlStateSelected];
EveryVC. tabBarItem. title = @ "";
UINavigationController * nvc = [[UINavigationController alloc] initWithRootViewController: everyVC];
[Self addChildViewController: nvc];
}
NSLog (@"