2010-09-25 60 views
3

想为我选择的选项卡设置一个自定义背景,到目前为止,子类化是他们自定义UITAbBar/UITabBarItem的方式。UITabBarItem选定的选项卡背景:自定义?

问题是:有人知道(或知道我在哪里可以找到)设置背景的属性是什么?

选定选项卡周围有一个较浅的黑色/灰色圆形框。这正是我想要改变的。

iOS 4.1随附Game Center,并且他们已经完全定制了UITabBar。我期待着做类似的事情。

回答

1

为了达到上述目的,您将需要创建一个自定义的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插座与选项卡栏控制器相关联。