UIKit의 단일 예: UITABBarController Block

2163 단어
//단일 예
#import 
//    :                         (      )

//                    

//         

@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;
}

좋은 웹페이지 즐겨찾기