自定义UITabBarController - 最佳方法

时间:2013-02-11 14:56:26

标签: iphone ios objective-c uitabbarcontroller

创建完全自定义UITabBarController外观的最佳方式是什么?

我需要完全自定义其大小,动画等等。

我所拥有的解决方案是使用UIView作为tabbarcontroller,然后根据UIView上选择的按钮替换其上方的UIView

最好的方法是什么?

1 个答案:

答案 0 :(得分:0)

这是一个非常好的指南: http://www.felipecypriano.com/2012/02/27/how-to-customize-uitabbar-on-ios-5/

此示例取自该网站:

基本上创建一个backgroundImage,selectionIndicatorImage,根据需要调整字体。

// Probably put these in your AppDelegate, setup the background and selection image
[[[self tabBarController] tabBar] setBackgroundImage:[UIImage imageNamed:@"background"]];
[[[self tabBarController] tabBar] setSelectionIndicatorImage:[UIImage imageNamed:@"selected"]];

// In your VC which is inside the tab bar
- (id)init {
    self = [super initWithNibName:@"MyNibName" bundle:nil];
    if (self) {
        self.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"The Title" image:nil tag:0];
        [[self tabBarItem] setFinishedSelectedImage:[UIImage imageNamed:@"tab_icon"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_icon"]];
        [[self tabBarItem] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor, nil] forState:UIControlStateNormal];
    }
}