UIKit之單例 UITabBarController ?Block

// 單例

#import <Foundation/Foundation.h>
// 單例類: 單例類可以初始化一個單例對象 他只被初始化一次 (節省內存空間)

// 他的生命周期 和整個程序的生命周期一樣

// 單例一般用來傳值

@interface DateHandle : NSObject

@property(nonatomic,retain)NSString *name;

// 類方法( 單例必須有 )
+ (instancetype)shareHandle;

@end

#import "DateHandle.h"

// 1. 單例對象 放在靜態區
static DateHandle * handle = nil;

@implementation DateHandle
// 2. 實現方法
+(instancetype)shareHandle
{
    if (handle == nil) {
        handle = [[DateHandle alloc]init];
        handle.name = @"張三";
    }
    return handle;
}
@end


self.label.text = [DateHandle shareHandle].name;


// UITabBarController
    // 外表
    //[[UINavigationBar appearance] setTranslucent:NO];
    [[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:@"6.png"] forBarMetrics:UIBarMetricsDefault];

    GreenViewController *greenVC = [[GreenViewController alloc]init];
    UINavigationController *greenNC = [[UINavigationController alloc]initWithRootViewController:greenVC];
    // 系統的tabBar
    greenNC.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemHistory tag:100];
   
    RedViewController *redVC  = [[RedViewController alloc]init];
    UINavigationController *redNC = [[UINavigationController alloc]initWithRootViewController:redVC];
    UIImage *image1 = [UIImage imageNamed:@"5.png"];
    UIImage *image2 = [UIImage imageNamed:@"6.png"];
    redNC.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"聯系人" image:image1 selectedImage:image2];
    redNC.tabBarItem.badgeValue = @"das";

    UITabBarController *tabVC = [[UITabBarController alloc]init];
    // 存放 他管理的 Controller
    tabVC.viewControllers = @[greenNC,redNC,blueNC,yellowNC,blackNC,purpleNC];
    tabVC.delegate = self;
    self.window.rootViewController = tabVC;
    // 當前位置
    tabVC.selectedIndex = 2;
   
    // 改顏色
//    tabVC.tabBar.tintColor = [UIColor redColor];
//    tabVC.tabBar.barTintColor = [UIColor blackColor];
 

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    viewController.tabBarItem.badgeValue = nil;
}
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 單例模式(SingletonPattern)一般被認為是最簡單、最易理解的設計模式,也因為它的簡潔易懂,是項目中最...
    成熱了閱讀 4,285評論 4 34
  • 單例模式(Singleton Pattern)是最簡單的一種設計模式。下面讓我們開始學習單例模式。 一、基本介紹 ...
    冰鑒IT閱讀 1,121評論 1 19
  • 概述 單例模式是應用最廣的模式之一,在應用這個模式時,單例對象的類必須保證只有一個實例存在。許多時候整個系統只需要...
    劉滌生閱讀 1,030評論 0 5
  • coding 的演示功能不讓用,原來搭建的博客訪問不了了。索性將全部博客遷移到簡書,這篇是舊文章,歡迎大家以后來簡...
    小笨狼閱讀 859評論 0 14
  • 上篇文章分析了文件操作中的打開和讀取操作。這篇文章我們來分析一下文章的寫入和關閉操作。 寫入文件 在討論寫文件操作...
    木傀儡閱讀 281評論 0 0