UITabBar中的自定义颜色

UITabBar中的自定义颜色

是否可以在UITabBar中使用自定义颜色和背景图像?我意识到Apple希望每个人都使用相同的蓝色和灰色标签栏,但有没有办法自定义这个?

其次,即使我创建自己的TabBar视图控制器,以及自定义图像,这是否会违反Apple的人机界面指南?


慕田峪4524236
浏览 560回答 3
3回答

冉冉说

我在Silent Mac Design找到了答案。我这样实现:首先创建UITabBarContoller的子类//&nbsp;CustomUITabBarController.h#import&nbsp;<UIKit/UIKit.h>@interface&nbsp;CustomUITabBarController:&nbsp;UITabBarController&nbsp;{ &nbsp;&nbsp;IBOutlet&nbsp;UITabBar&nbsp;*tabBar1;}@property(nonatomic,&nbsp;retain)&nbsp;UITabBar&nbsp;*tabBar1;@end&nbsp;//&nbsp;CustomUITabBarController.m#import&nbsp;"CustomUITabBarController.h"@implementation&nbsp;CustomUITabBarController@synthesize&nbsp;tabBar1;-&nbsp;(void)viewDidLoad&nbsp;{ &nbsp;&nbsp;[super&nbsp;viewDidLoad]; &nbsp;&nbsp;CGRect&nbsp;frame&nbsp;=&nbsp;CGRectMake(0.0,&nbsp;0,&nbsp;self.view.bounds.size.width,&nbsp;48); &nbsp;&nbsp;UIView&nbsp;*v&nbsp;=&nbsp;[[UIView&nbsp;alloc]&nbsp;initWithFrame:frame]; &nbsp;&nbsp;[v&nbsp;setBackgroundColor:[[UIColor&nbsp;alloc]&nbsp;initWithRed:1.0 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;green:0.0 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;blue:0.0 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alpha:0.1]]; &nbsp;&nbsp;[tabBar1&nbsp;insertSubview:v&nbsp;atIndex:0]; &nbsp;&nbsp;[v&nbsp;release];}@end在你的Nib文件中用CustomUITabBarController替换你的TabBar控制器的类。

qq_花开花谢_0

仅供参考,从iOS 5开始,您可以自定义UITabBar的各个方面,包括使用backgroundImage属性设置其背景图像。iOS 5中新的UITabBar&nbsp;“自定义外观”属性包括:backgroundImage&nbsp; selectedImageTintColor&nbsp;&nbsp; selectionIndicatorImage&nbsp;&nbsp; tintColor鉴于Apple已经在iOS 5中引入了这些方法,那么他们可能会更加同情为早期操作系统定制UITabBar。这个网站说Twitter应用程序使用自定义标签栏,所以这可能是Apple将这样的应用程序放入App Store的更多原因,但不能保证!
打开App,查看更多内容
随时随地看视频慕课网APP