UITabBarController练习

#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController

@end
#import "RootViewController.h"

@implementation RootViewController

-(void)viewWillAppear:(BOOL)animated
{
    UITabBarItem* item = self.tabBarController.tabBar.items[0];
    item.badgeValue = @"12";
}
@end
#import "AppDelegate.h"
#import "RootViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    RootViewController* r1= [[RootViewController alloc] init];
    UITabBarItem* item1 = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:0];
    r1.tabBarItem = item1;
    r1.title = @"第一个";
    r1.tabBarItem.title =@"第一个";
    r1.tabBarController.title=@"第一个";
    r1.view.backgroundColor = [UIColor blueColor];
    RootViewController* r2= [[RootViewController alloc] init];
    r2.title = @"第二个";
    r2.tabBarItem.image = [UIImage imageNamed:@"3.png"];
    r2.view.backgroundColor = [UIColor redColor];
    
    RootViewController* r3= [[RootViewController alloc] init];
    UITabBarItem* item3 = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemHistory tag:2];
    r3.tabBarItem = item3;
    r3.view.backgroundColor = [UIColor greenColor];
    
    RootViewController* r4= [[RootViewController alloc] init];
    UITabBarItem* item4 = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:3];
    r4.tabBarItem = item4;
    r4.view.backgroundColor = [UIColor grayColor];
    
    RootViewController* r5= [[RootViewController alloc] init];
    UITabBarItem* item5 = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:4];
    r5.tabBarItem = item5;
    r5.view.backgroundColor = [UIColor darkGrayColor];
    
    RootViewController* r6= [[RootViewController alloc] init];
    UITabBarItem* item6 = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:5];
    r6.tabBarItem = item6;
    r6.view.backgroundColor = [UIColor darkGrayColor];
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    UITabBarController* t = [[UITabBarController alloc] init];
    t.tabBar.backgroundColor = [UIColor brownColor];
    t.viewControllers = @[r1,r2,r3,r4,r5,r6];
    self.window.rootViewController = t;
    
    [self.window makeKeyAndVisible];
    return YES;
}

个人对这个ui组件使用的理解

1,虽然这个UITabBarController继承于UIViewController,但UIViewController也保留了访问其属性,这样方便了通讯。

2,即使继承于UINavigationController的话,也能访问其TabBarController属性,就是多了导航属性,如多了导航条。

3,UITabBarController是数组管理,每个元素是个ViewController,同时又有tabBar属性,每个元素是tabBarItem,这个可以替换。

4,tabBar最多显示5个元素,大于5个会显示更多按钮。

5,使用了系统提供的tabBarItem后,对其设置title和图片都不其作用了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值