2013-02-11 36 views
4
//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; 
} 

//如何在不向tabbaritem添加任何//圖像的情況下將第一個tabbar項目標題「文章視圖」添加到中心?將iOS TabBar項目標題調整到它的中心

//類似於下面的tabbar物品截圖。

[1]: http://i.stack.imgur.com/xBpVH.png 


Thanks in advance. 
+0

感謝您的問題,並感謝您的答案 – Abo3atef 2013-12-05 01:04:33

回答

14

更換initWithNibName方法

- (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);這條線在這裏調整圖像的用於tabBarItem的方式的位置:

移在x方向上的圖像「+ 5'和從 默認位置的y方向'-5'。

UIEdgeInsetsMake並玩得開心。乾杯。

+0

感謝您幫助我的兄弟.. 我問你,而不是工作的形象,而是我應該改變標題的位置,它得到修復。 – 2013-02-11 12:51:51

+0

很高興我可以幫助..給出答案檢查,如果你覺得;):) – croyneaus4u 2013-02-11 16:39:01