2015-10-23 4 views
7

Я реализую UITabBar в другом UITabBar. Моя проблема в том, что вторая ширина TabBar остается постоянной независимо от размера экрана. Это выделяется на больших экранах. Я прилагаю скриншот, чтобы вы поняли лучше. Выбор обозначается с помощью синего фона First TabBar on Top Second on the bottomШирина UITabBar не увеличивается с размером экрана

Second Tab in Second TabBar Selected

Third tab Selected in Second TabBar Controller

Вот код:

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; 

Скриншоты из iPhone6 ​​Plus

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

+0

Является ли это UITabBar по умолчанию? Как вы выбираете кнопки? – user3820674

+0

Просто добавленный код для этого –

+0

Как ваш автозапуск настроен? – Kreiri

ответ

5

Благодарим за фрагмент кнопок с подсветкой.
Вам нужно что-то вроде этого?
Книжная ориентация:

enter image description here


альбомной ориентации:

enter image description here

код моего ViewController:

#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

Не для ландшафтной ориентации. приложение предназначено только для работы в портретном режиме. Я хочу, чтобы ширина увеличивалась с помощью экранов –

+0

Таким образом, метод viewDidLayoutSubviews, вероятно, не нужен. Пожалуйста, отметьте ответ как можно скорее, если он вам поможет. – user3820674

+0

это не помогло. –

Смежные вопросы