2016-07-12 3 views

答えて

0

タブアイテムの背景を追加する場合のみ可能です。背景を作成するために画像またはサブビューを追加できます。 あなたは、プログラムUITabBarの背景にすることができます。

#define SEPARATOR_WIDTH 0.4f 
#define SEPARATOR_COLOR [UIColor whiteColor] 

- (void) setupTabBarSeparators { 
    CGFloat itemWidth = floor(self.tabBar.frame.size.width/self.tabBar.items.count); 

    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tabBar.frame.size.width, self.tabBar.frame.size.height)]; 
    for (int i=0; i<self.tabBar.items.count - 1; i++) { 
     UIView *separator = [[UIView alloc] initWithFrame:CGRectMake(itemWidth * (i +1) - SEPARATOR_WIDTH/2, 0, SEPARATOR_WIDTH, self.tabBar.frame.size.height)]; 
     [separator setBackgroundColor:SEPARATOR_COLOR]; 
     [bgView addSubview:separator]; 
    } 

    UIGraphicsBeginImageContext(bgView.bounds.size); 
    [bgView.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    UIImage *tabBarBackground = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    [[UITabBar appearance] setBackgroundImage:tabBarBackground]; 
} 
+0

私は下のタブバーコントローラを求めていますが、あなたはB青と緑tabbaritem –

+0

ワット/区切り線を見ることができるようにタブの商品数W/Bのセパレータを追加したいです@SukhdeepSinghKalraは、下部のタブバーで動作します。試しましたか ? – Yatendra

関連する問題