//TabBarController code:
self.delegate=self;
self.tabBarController.tabBar.delegate=self;
CGRect viewFrame=self.tabBar.frame;
viewFrame.origin.y -=0;![enter image description here][1]
viewFrame.origin.x -=0;
viewFrame.size.height=30;
self.tabBar.frame=viewFrame;
firstViewController = [[FirstViewController alloc] initWithNibName:nil bundle:NULL];
secondViewController = [[SecondViewController alloc] initWithNibName:nil bundle:NULL];
NSArray *twoViewControllers = [[NSArray alloc] initWithObjects:
self.firstViewController, self.secondViewController, nil];
self.viewControllers=twoViewControllers;
// ====================================================
//
// FirstViewController code in initWithNibName:
//
// To set the title of the first tabbar item:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = @"Article view";
NSLog(@"count = %d",[self.tabBarController.tabBar.items count]);
}
return self;
}
//How can i make the first tabbar item title "Article View" to the Center without adding any //image to the tabbaritem ?
// similar to the below tabbar items screenshot.
[1]: http://i.stack.imgur.com/xBpVH.png
Thanks in advance.
Replace the initWithNibName
method
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = @"Article view";
self.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
NSLog(@"count = %d",[self.tabBarController.tabBar.items count]);
}
return self;
}
self.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
this line here adjusts the position of the image for the tabBarItem in the manner :
Shift the image in x-direction '+5' and in y-direction '-5' from the default position.
Play with UIEdgeInsetsMake
and have fun. Cheers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With