UITabBarItem 选定的选项卡背景:自定义?

发布于 2024-09-24 17:34:48 字数 208 浏览 1 评论 0原文

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

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

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

iOS 4.1 附带了 Game Center,并且他们完全自定义了 UITabBar。我想做类似的事情。

Would like to set a custom background for my selected tabs, thus far, subclassing is they way I'm customizing the UITAbBar/UITabBarItem.

The question is: Does anybody know (or know where I could find ) what the property is that sets the background?

There is a lighter black/grey rounded box around the selected tab. That is what I'm aiming at changing.

iOS 4.1 ships with Game Center, and they've completely customized the UITabBar. I'm looking to do something similar.

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

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

发布评论

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

评论(1

娇柔作态 2024-10-01 17:34:48

为了实现上述目标,您需要创建一个自定义 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 出口关联到选项卡栏控制器。

In order to achieve the above you are going to need to create a custom UITabBarController class.

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

You'll then need to change MainWindow.xib and choose the Tab Bar Controller. Within the Property inspector you need to change the class to your custom class, then associate the tabBar1 outlet to the Tab Bar Controller.

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