为了账号安全,请及时绑定邮箱和手机立即绑定

UITabBar中的自定义颜色

UITabBar中的自定义颜色

慕田峪4524236 2019-07-29 16:55:01
UITabBar中的自定义颜色是否可以在UITabBar中使用自定义颜色和背景图像?我意识到Apple希望每个人都使用相同的蓝色和灰色标签栏,但有没有办法自定义这个?其次,即使我创建自己的TabBar视图控制器,以及自定义图像,这是否会违反Apple的人机界面指南?
查看完整描述

3 回答

?
冉冉说

TA贡献1877条经验 获得超1个赞

我在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文件中用CustomUITabBarController替换你的TabBar控制器的类。


查看完整回答
反对 回复 2019-07-29
?
qq_花开花谢_0

TA贡献1835条经验 获得超6个赞

仅供参考,从iOS 5开始,您可以自定义UITabBar的各个方面,包括使用backgroundImage属性设置其背景图像。

iOS 5中新的UITabBar “自定义外观”属性包括:

backgroundImage 
selectedImageTintColor  
selectionIndicatorImage  
tintColor

鉴于Apple已经在iOS 5中引入了这些方法,那么他们可能会更加同情为早期操作系统定制UITabBar。这个网站说Twitter应用程序使用自定义标签栏,所以这可能是Apple将这样的应用程序放入App Store的更多原因,但不能保证!


查看完整回答
反对 回复 2019-07-29
  • 3 回答
  • 0 关注
  • 557 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信