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;
}

//タブバーアイテムに画像を追加せずに//最初のタブバーアイテムのタイトル「ArticleView」を中央に作成するにはどうすればよいですか?

//以下のタブバーアイテムのスクリーンショットに似ています。

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


Thanks in advance.
4

1 に答える 1

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楽しんでください。乾杯。

于 2013-02-11T12:36:56.560 に答える