是否可以在 UITabBar 中使用自定义颜色和背景图像?我知道 Apple 希望每个人都使用相同的蓝色和灰色标签栏,但有没有办法自定义呢?
其次,即使我要创建自己的类似 TabBar 的 View Controller 以及自定义图像,这会违反 Apple 的人机界面指南吗?
最佳答案
我在 Silent Mac Design 找到了答案.
我是这样实现的:
首先创建一个UITabBarContoller的子类
// 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];
CGRect frame = CGRectMake(0.0, 0, self.view.bounds.size.width, 48);
UIView *v = [[UIView alloc] initWithFrame:frame];
[v setBackgroundColor:[[UIColor alloc] initWithRed:1.0
green:0.0
blue:0.0
alpha:0.1]];
[tabBar1 insertSubview:v atIndex:0];
[v release];
}
@end
并在您的 Nib 文件中将 TabBar Controller 的类替换为 CustomUITabBarController。
关于iphone - UITabBar 中的自定义颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/675433/