IOS學習筆記UITabBarController使用教程

來源:互聯網
上載者:User

實現一個簡單的UITabBar:

AppDelegate.m

 代碼如下 複製代碼

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    
    
    UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(320/2-140/2, 80, 140, 40)];
    lab.text = @"王振";
    lab.textAlignment = UITextAlignmentCenter;
    lab.backgroundColor = [UIColor blueColor];
    [self.window addSubview:lab];
    
    //your code
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(320/2-140/2,480/2-40/2, 140, 40)];
    label.text = @"Hello World";
    label.backgroundColor = [UIColor cyanColor];
    label.textAlignment = UITextAlignmentCenter;
    [self.window addSubview:label];
    
    HomeViewController *view1 = [[HomeViewController alloc]init];
    UINavigationController *v1 = [[UINavigationController alloc]initWithRootViewController:view1];
 
    
    MessageViewController *view2 = [[MessageViewController alloc]init];
    UINavigationController *v2 = [[UINavigationController alloc]initWithRootViewController:view2];
    
    SearchViewController *view3 = [[SearchViewController alloc]init];
    UINavigationController *v3 = [[UINavigationController alloc]initWithRootViewController:view3];
    
    SettingViewController *view4 = [[SettingViewController alloc]init];
    UINavigationController *v4 = [[UINavigationController alloc]initWithRootViewController:view4];
    
    
    //NSArray *arr = @[view1,view2,view3,view4];
    
    NSArray *viewControllers = [NSArray arrayWithObjects:v1,v2,v3,v4 , nil];
 
    
    UITabBarController *mainViewController = [[UITabBarController alloc]init];
    mainViewController.viewControllers = viewControllers;
    //[mainViewController setViewControllers:mainViewController];
    
    //[mainViewController release];
    [UIApplication sharedApplication].applicationIconBadgeNumber = 2;
    
    [self.window setRootViewController:mainViewController];
    
    
    return YES;
}

HomeViewController.m

 代碼如下 複製代碼
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.title = @"首頁";
        self.tabBarItem.badgeValue = @"New";
 
    }
    return self;
}
 
-(void)loadView
{
    UIView *view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    view.backgroundColor = [UIColor whiteColor];
    self.view = view;
 
}

技巧:
給Iphone表徵圖添加數字提示:self.tabBarItem.badgeValue = 8;

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.