storybored 線拖tabbarvc app去儲存對象

來源:互聯網
上載者:User

標籤:

最終:

 

main.storyboard

 

 

BeyondViewController.m中有一句關鍵代碼,設定tabbarItem圖片的樣式(30*30)

 

////  BeyondViewController.m//  17_控制器切換2_tabbarController////  Created by beyond on 14-7-31.//  Copyright (c) 2014年 com.beyond. All rights reserved.//#import "BeyondViewController.h"#import "NanaViewController.h"#import "SettingViewController.h"@interface BeyondViewController ()@end@implementation BeyondViewController- (void)viewDidLoad{    [super viewDidLoad];        NSLog(@"view did loaded");        // UITabbarController裡面的tabbarItem中的圖片需要特殊API處理之後,才能正常顯示    UIImage *img = [UIImage imageNamed:@"home"];    UIImage *img_selected = [UIImage imageNamed:@"home_s"];    // 設定圖片 渲染 模式    img = [img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];    // 設定圖片 渲染 模式    img_selected = [img_selected imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];        // 構造方法產生 UITabBarItem    UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"" image:img selectedImage:img_selected];        // 設定當前控制器的 tabBarItem屬性    self.tabBarItem = item;    self.tabBarItem.title = @"首頁";    self.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d",1] ;            // 預設情況下,app運行之後,只執行第一個控制器的view did load方法,因此,要得到UITabBarController容器中所有的控制器,調用其自訂的一個方法,設定它們自己的tabbaritem樣式        // 先得到父容器UITabBarController,有了它,就有了所有的控制器執行個體的引用    UITabBarController *parentCtrl = self.parentViewController;    // 得到容器UITabBarController中所有的子控制器    NSArray *children = [parentCtrl childViewControllers];    // 調用對應的子控制器的 自訂方法,設定它們自己的tabbaritem樣式    NanaViewController *nanaVC = (NanaViewController *)[children objectAtIndex:1];    [nanaVC setTabBarItemDIY];        // 調用對應的子控制器的 自訂方法,設定它們自己的tabbaritem樣式    SettingViewController *setVC = (SettingViewController *)[children objectAtIndex:2];    [setVC setTabBarItemDIY];    }@end



 

 

NanaViewController.h

////  NanaViewController.h//  17_控制器切換2_tabbarController////  Created by beyond on 14-7-31.//  Copyright (c) 2014年 com.beyond. All rights reserved.//#import <UIKit/UIKit.h>@interface NanaViewController : UIViewController// 自訂方法,設定自己的tabbaritem樣式- (void) setTabBarItemDIY;@end



 

NanaViewController.m

 

 

 

////  NanaViewController.m//  17_控制器切換2_tabbarController////  Created by beyond on 14-7-31.//  Copyright (c) 2014年 com.beyond. All rights reserved.//#import "NanaViewController.h"@interface NanaViewController ()@end@implementation NanaViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];    if (self) {        // Custom initialization    }    return self;}- (void)viewDidLoad{    [super viewDidLoad];    // Do any additional setup after loading the view.    NSLog(@"view did loaded  2");        }// 自訂方法,設定自己的tabbaritem樣式- (void) setTabBarItemDIY{    // UITabbarController裡面的tabbarItem中的圖片需要特殊API處理之後,才能正常顯示    UIImage *img = [UIImage imageNamed:@"nana"];    UIImage *img_selected = [UIImage imageNamed:@"nana_s"];    // 設定圖片 渲染 模式    img = [img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];    // 設定圖片 渲染 模式    img_selected = [img_selected imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];        // 構造方法產生 UITabBarItem    UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"" image:img selectedImage:img_selected];        // 設定當前控制器的 tabBarItem屬性    self.tabBarItem = item;    self.tabBarItem.title = @"娜娜";    self.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d",2] ;}@end



 

 

SettingViewController.h

////  SettingViewController.h//  17_控制器切換2_tabbarController////  Created by beyond on 14-7-31.//  Copyright (c) 2014年 com.beyond. All rights reserved.//#import <UIKit/UIKit.h>@interface SettingViewController : UIViewController// 自訂方法,設定自己的tabbaritem樣式- (void) setTabBarItemDIY;@end



 

SettingViewController.m

 

////  SettingViewController.m//  17_控制器切換2_tabbarController////  Created by beyond on 14-7-31.//  Copyright (c) 2014年 com.beyond. All rights reserved.//#import "SettingViewController.h"@interface SettingViewController ()@end@implementation SettingViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];    if (self) {        // Custom initialization    }    return self;}- (void)viewDidLoad{    [super viewDidLoad];    // Do any additional setup after loading the view.    NSLog(@"view did loaded  3");        }// 自訂方法,設定自己的tabbaritem樣式- (void) setTabBarItemDIY{    // UITabbarController裡面的tabbarItem中的圖片需要特殊API處理之後,才能正常顯示    UIImage *img = [UIImage imageNamed:@"setting"];    UIImage *img_selected = [UIImage imageNamed:@"setting_s"];    // 設定圖片 渲染 模式    img = [img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];    // 設定圖片 渲染 模式    img_selected = [img_selected imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];        // 構造方法產生 UITabBarItem    UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"" image:img selectedImage:img_selected];        // 設定當前控制器的 tabBarItem屬性    self.tabBarItem = item;    self.tabBarItem.title = @"我的";    self.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d",3] ;}@end



 

storybored 線拖tabbarvc app去儲存對象

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.