如何制作中央凸起的tabbar项目?

时间:2011-12-14 11:35:02

标签: iphone ios uitabbaritem

起初我想说我是iPhone应用程序开发的新手。我想制作一个tabbaritem,当我选择tabbar的项目然后它应该看起来像那样

enter image description here

非常感谢提前。

5 个答案:

答案 0 :(得分:3)

知道它已被回答,但想提供另一种方法。

根据文档,对UITabBarController进行子类化是一个坏主意。当我真正尝试使用UIImagePickerController作为子类标签栏后面的一个视图控制器时,我也没有遇到麻烦。

我采用了一种更简单的方法,只是将一个uibutton覆盖在tabbar项目上。示例项目可以在这里找到:

https://github.com/group6/RaisedCenterButton

这只是一个例子。您仍然需要完成将其合并到应用程序中的工作。

答案 1 :(得分:2)

使用此Article

中的信息

答案 2 :(得分:1)

这已在很多教程中介绍过。大多数这些应用程序如何实现这一效果的是他们将自定义UIButton放在中心标签栏顶部的Tab Bar上,其风格类似。

iDev Recipes有一个很好的教程,代码示例

答案 3 :(得分:0)

我建议不要这样做。 iOS用户习惯熟悉的标签栏功能。突出显示足以让他们知道他们在哪个标签上。

您的设计理念非常具有吸引力,但需要付出代价。条形项目旁边的栏上方区域被浪费,或者其他图标的大小必须减少。这将使其更难以使用,而不是更容易。

这是一个很好的提示:从忙碌的生活中抽出2个小时,从封面到封面阅读Apple Human Interface Guidelines for iOS。它令人着迷的阅读,将为您提供这样的设计问题的良好指导。

答案 4 :(得分:0)

为此,您需要通过Sub classing UITabBarController创建自定义标签栏。

TabBarController.h文件:

@interface TabBarController : UITabBarController<UITabBarControllerDelegate>
{
    UITabBarController *tabController;

    UIImageView *img1;
    UIImageView *img2;
    UIImageView *img3;
    UIImageView *img4;
}

.m文件

- (void)viewDidLoad 
{       
    [self loadTabView];
    //[self viewWillAppear:YES];
    [super viewDidLoad];        
}

- (void) loadTabView 
{
    tabController = [[UITabBarController alloc] init];
    tabController.delegate = self;
    tabController.tabBar.backgroundColor = [UIColor clearColor];

    //set offset for tabbar items images. 
    int topOffset = 6;
    int bottomOffset = 6;
    UIEdgeInsets imageInset = UIEdgeInsetsMake(topOffset, 0, -bottomOffset, 0);

    [self.view addSubview:tabController.view];
}

// reset the background image in custom tabbar.
- (void) setTabBarBackground {

    UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"btnbg.png"]];
    img.frame = CGRectOffset(img.frame, 0, 1);
    img.frame = CGRectMake(img.frame.origin.x, img.frame.origin.y-1, img.frame.size.width, img.frame.size.height);
    [tabController.tabBar insertSubview:img atIndex:0];
    [img release];

}

// reset the background image in custom tabbar.
- (void) resetTabBar : (NSString *) tabid
{   
    [img1 removeFromSuperview];

    NSLog(@"tab id - %@",tabid);
    switch ([tabid intValue]) {
        case 0:
            img1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tab-1.jpg"]];
            break;
        case 1:
            img1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tab-2.jpg"]];
            break;
        case 2:
            img1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tab-3.jpg"]];
            break;
        case 3:
            img1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tab-4.jpg"]];
            break;
        case 4:
            img1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tab-5.jpg"]];
            break;
        default:
            break;
    }

    img1.frame = CGRectOffset(img1.frame, 0, 1);
    [tabController.tabBar insertSubview:img1 atIndex:0];
    [tabController.tabBar bringSubviewToFront:img1];
    [img1 release];

}

// here push View controllers
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
}

希望它能给你一些想法......

相关问题