我怎样才能制作中央凸起的标签栏项目?

发布于 2024-12-21 15:19:18 字数 150 浏览 0 评论 0原文

首先我想说我是 iPhone 应用程序开发的新手。当我选择选项卡栏的一项时,我想制作一个选项卡项,那么它应该看起来像

在此处输入图像描述

提前非常感谢。

At first I want to say that i am new in iPhone application development.I want to make a tabbaritem when i will select a item of the tabbar then it should be look like that

enter image description here

Many Thanks In Advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

街角迷惘 2024-12-28 15:19:18

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

根据文档,子类化 UITabBarController 是一个坏主意。当我实际尝试使用 UIImagePickerController 作为子类化选项卡栏后面的视图控制器之一时,我也遇到了无穷无尽的麻烦。

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

https://github.com/group6/RaishedCenterButton

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

Know it's already been answered, but wanted to offer an alternative approach.

Subclassing UITabBarController is a bad idea, according to the docs. I also had no end of trouble when I actually tried to use a UIImagePickerController as one of the view controllers behind the subclassed tabbar.

I took a much simpler approach just overlaying a uibutton over the tabbar item. Example project can be found here:

https://github.com/group6/RaisedCenterButton

It's just an example though. You're still going to need to do the work to incorporate it into an app.

东走西顾 2024-12-28 15:19:18

这已经在很多教程中进行了介绍。这些应用程序中的大多数实现这种效果的方式是在中间的选项卡栏顶部放置一个自定义的 UIButton,该按钮的样式与选项卡栏类似。

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

This has been covered in quite a few tutorials. How most of these apps achieve the effect is they put a custom UIButton which follows similar styling to the Tab Bar on top of the tab bar in the center.

iDev Recipes has an excellent tutorial with the code example

貪欢 2024-12-28 15:19:18

为此,您需要通过子类 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 {
}

希望它能给您带来想法。

For this you need to create custom tab bar by Sub classing UITabBarController.

TabBarController.h file :

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

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

.m file

- (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 {
}

Hope it gives you idea..

戈亓 2024-12-28 15:19:18

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

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

这里有一个很好的建议:从忙碌的生活中抽出 2 个小时阅读 Apple iOS 人机界面指南从头到尾。本书引人入胜,将为您提供解决此类设计问题的良好指导。

I would advise not to do this. iOS users are used to the familiar tab bar functionality. The highlight is sufficient to let them know on which tab they are.

Your design idea is very attractive, but it comes at a cost. The area above the bar beside the rased bar item is wasted, or the size of other icons have to be reduced. This will make it more difficult to use, not easier.

Here is a good tip: take 2 hours out of your busy life and read the Apple Human Interface Guidelines for iOS from cover to cover. Its fascinating reading and will give you good guidance for design questions like this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文