UITabBarItem Selected Tab Background: Custom?

I would like to set up a custom background for my selected tabs, while subclasses are the way I customize UITAbBar / UITabBarItem.

Question: Does anyone know (or know where I could find) that the property sets the background?

There is a lighter black / gray rounded rectangle around the selected tab. This is exactly what I want to change.

iOS 4.1 ships with Game Center, and they have fully configured UITabBar. I am looking for something like that.

+3
source share
1 answer

To achieve the above, you will need to create a custom class UITabBarController.

CustomUITabBarController.h

#import <UIKit/UIKit.h>

@interface CustomUITabBarController: UITabBarController {
   IBOutlet UITabBar *tabBar1;
}

@property (nonatomic, retain) UITabBar *tabBar1;

@end

CustomUITabBarController.m

#import "CustomUITabBarController.h"

@implementation CustomUITabBarController

@synthesize tabBar1;

- (void)viewDidLoad {
   [super viewDidLoad];
   tabBar1.backgroundColor = [UIColor clearColor];
   CGRect frame = CGRectMake(0, 0, 480, 49);
   UIView *v = [[UIView alloc] initWithFrame:frame];
   UIImage *i = [UIImage imageNamed:@"customImage.png"];
   UIColor *c = [[UIColor alloc] initWithPatternImage:i];
   v.backgroundColor = c;
   [c release];
   [[self tabBar] insertSubview:v atIndex:0];
   [v release];
}

@end

MainWindow.xib . , tabBar1 .

+1

Source: https://habr.com/ru/post/1766509/


All Articles