iphone - UITabBar 中的自定义颜色

标签 iphone objective-c

是否可以在 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/

相关文章:

ios - AVPlayer 到全屏,顶部和底部没有黑条

objective-c - NSString 和 NSTextfield 的东西

ios - 使用动画以编程方式更改 tabbarController 的选项卡

ios - ShareKit 是否仍然有效 - 2015?如果可以,是否可以在 Swift 中实现?

objective-c - 如何从 NSTableView 中删除所有 NSTableColumns?

objective-c - 是否可以直接将函数指针作为 block 参数传递?

ios - iOS中pod install命令的工作流程

iphone - 我们可以在 iPhone 中以编程方式打开/关闭 GPS 吗?

iphone - 使用 Storyboard时何时观察模型数据

iphone - UIActionSheet 着色