【问题标题】:UITabBarItem Selected Tab Background: Custom?UITabBarItem 选定的选项卡背景:自定义?
【发布时间】:2010-09-25 03:31:57
【问题描述】:

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

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

所选标签周围有一个较浅的黑色/灰色圆形框。这就是我要改变的目标。

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

【问题讨论】:

    标签: custom-controls uitabbar uitabbaritem


    【解决方案1】:

    为了实现上述目标,您需要创建一个自定义 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 并选择 Tab Bar Controller。在属性检查器中,您需要将类更改为您的自定义类,然后将tabBar1 插座与标签栏控制器相关联。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-27
      • 1970-01-01
      • 2014-05-07
      • 2017-04-24
      • 1970-01-01
      • 1970-01-01
      • 2013-11-22
      • 2018-08-27
      相关资源
      最近更新 更多