2015-10-23 19 views
7

ile artmıyor UITabBar'u başka bir UITabBar içinde uyguluyorum. Benim sorunum, ikinci TabBar genişliğinin ekran boyutundan bağımsız olarak sabit kalmasıdır. Bu büyük ekranlarda çok şey öne çıkıyor. Daha iyi anlaman için ekran görüntüsü ekliyorum.UITabBar genişliği, ekran boyutu

Second Tab Of First TabBar selected(not part of the question, just to show the full picture)

iPhone6 ​​Plus

GRect rect = CGRectMake(0, 0, self.tabBar.frame.size.width/2, self.tabBar.frame.size.height); 
    UIGraphicsBeginImageContext(rect.size); 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSetFillColorWithColor(context, 
            [[UIColor colorWithRed:102.0/255.0 green:197.0/255.0 blue:234.0/255.0 alpha:1.0] CGColor]); 

    CGContextFillRect(context, rect); 
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    self.tabBar.selectionIndicatorImage = img; 

ekran: Seçim kod mavi bir arka plan First TabBar on Top Second on the bottom

Second Tab in Second TabBar Selected

İşte

Third tab Selected in Second TabBar Controller

oluyor kullanılarak belirtilir

+0

Bu varsayılan UITabBar mı? Düğmeleri nasıl değiştiriyorsun? – user3820674

+0

Bunun için sadece –

+0

kodunu ekledim Otomatik oynatma ayarınız nasıl? – Kreiri

cevap

5

Vurgulama düğmelerinin snippet'i için teşekkür ederiz.
Böyle bir şey mi istediniz?
Dikey yönelim:

enter image description here


Yatay yönelim:

: enter image description here

Kod benim ViewController ait

#import "ViewController.h" 

@interface ViewController() 
@property (weak, nonatomic) IBOutlet UITabBar *tabBar; 
@property (weak, nonatomic) IBOutlet UITabBar *topTabBar; 

@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    [[UITabBar appearance] setTintColor:[UIColor redColor]]; 
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:20]} forState:UIControlStateNormal]; 
} 

- (void)viewDidLayoutSubviews { 

    [self highlightTabBarItems:self.tabBar]; 
    [self highlightTabBarItems:self.topTabBar]; 
} 

- (void)highlightTabBarItems:(UITabBar*)currentTabBar { 

    CGFloat highlightedWidth = self.view.frame.size.width/currentTabBar.items.count; 
    [currentTabBar setItemWidth:highlightedWidth]; 
    CGRect rect = CGRectMake(0, 0, highlightedWidth, currentTabBar.frame.size.height); 
    UIGraphicsBeginImageContext(rect.size); 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSetFillColorWithColor(context, [[UIColor colorWithRed:102.0/255.0 green:197.0/255.0 blue:234.0/255.0 alpha:1.0] CGColor]); 
    CGContextFillRect(context, rect); 
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    currentTabBar.selectionIndicatorImage = img; 
} 

@end 
+0

) Yatay yönlendirme için gelmeyecek şekilde ayarladım. Uygulama sadece portre modunda çalışacak şekilde tasarlanmıştır. Ekran genişliği –

+0

ile genişliğin artmasını istiyorum. Yöntem görünümüDidLayoutSubviews muhtemelen gerek yok. Size yardımcı olursa lütfen cevabı doğru olarak işaretleyiniz. – user3820674

+0

, yardım etmedi. –

İlgili konular