自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iOS開發(fā)-基礎(chǔ)框架

移動開發(fā)
本基礎(chǔ)框架主要包括UITabBarController,UINavigationController和UIBarButtonItem類的擴(kuò)展。主要解決子視圖創(chuàng)建過多,封裝帶有UINavigationController的子視圖創(chuàng)建,然后添加到UITabBarController的ChildViewController視圖中。針對UITabBarController的UITabBarItem的字體大小,顏色設(shè)置。廢話不多說,上代碼。

[[164113]]

本基礎(chǔ)框架主要包括UITabBarController,UINavigationController和UIBarButtonItem類的擴(kuò)展。主要解決子視圖創(chuàng)建過多,封裝帶有UINavigationController的子視圖創(chuàng)建,然后添加到UITabBarController的ChildViewController視圖中。針對UITabBarController的UITabBarItem的字體大小,顏色設(shè)置。廢話不多說,上代碼。

一.繼承UITabBarController創(chuàng)建的NPTabBarController

1.設(shè)置tabbar上面的字體樣式

  1. #pragma mark - 設(shè)置tabbar上面的字 setTitleTextAttributes 
  2. - (void)setTabBarTitleAttributesStyle 
  3.     NSMutableDictionary *attrs = [NSMutableDictionary dictionary]; 
  4.     //通常字體大小 
  5.     attrs[NSFontAttributeName] = [UIFont systemFontOfSize:16]; 
  6.     //通常字體顏色 
  7.     attrs[NSForegroundColorAttributeName] = [UIColor lightGrayColor]; 
  8.  
  9.     NSMutableDictionary *selectAttrs = [NSMutableDictionary dictionary]; 
  10.     //選中字體大小 
  11.     selectAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:16]; 
  12.     //選中字體顏色 
  13.     selectAttrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor]; 
  14.  
  15.     //UI_APPEARANCE_SELECTOR 外觀 
  16.     UITabBarItem *item = [UITabBarItem appearance]; 
  17.     //tabbar通常字體樣式 
  18.     [item setTitleTextAttributes:attrs forState:UIControlStateNormal]; 
  19.     //tabbar選中字體樣式 
  20.     [item setTitleTextAttributes:selectAttrs forState:UIControlStateSelected]; 

2.導(dǎo)航子視圖封裝

  1. #pragma mark - 導(dǎo)航子視圖封裝 
  2. - (void)setChildVC:(UIViewController *)ChildVC title:(NSString *)title image:(NSString *)image selectImgage:(NSString *)selectImage { 
  3.  
  4.     //注意視圖層級關(guān)系,最上邊時UINavigationController,創(chuàng)建一個視圖即給一個UINavigationController 
  5.     NPNavigationController *nav = [[NPNavigationController alloc] initWithRootViewController:ChildVC]; 
  6.     //子視圖顯示在UITabbarController上顯示的tabbar標(biāo)題 
  7.     nav.tabBarItem.title = title; 
  8.     //子視圖顯示在UITabbarController上未選中tabbar的圖片 
  9.     nav.tabBarItem.image = [UIImage imageNamed:image]; 
  10.     //子視圖顯示在UITabbarController上選中tabbar的圖片 
  11.     nav.tabBarItem.selectedImage = [UIImage imageNamed:selectImage]; 
  12.     //子視圖背景顏色 
  13.     nav.view.backgroundColor = [UIColor grayColor]; 
  14.     //注意標(biāo)題顯示是子視圖的標(biāo)題,非UINavigationController 
  15.     ChildVC.navigationItem.title = title; 
  16.     //添加子視圖 
  17.     [self addChildViewController:nav]; 
  18.  

二.繼承UINavigationController創(chuàng)建NPNavigationController

1.重寫-(void)pushVewController:(UIViewConntroller*)viewCOntroller animated:(Bool)animated方法

  1. - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated 
  2.  
  3.    //判斷self.childViewControllers是不是拿到所有子控制器,self.childViewControllers.count為0時,只有子控制器,干掉返回按鈕 
  4.    if (self.childViewControllers.count > 0) { 
  5.        //自定義返回按鈕 
  6.        UIButton *returnBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 
  7.        //設(shè)置title:返回 
  8.        [returnBtn setTitle:@"返回" forState:UIControlStateNormal]; 
  9.        //正常下image 
  10.        [returnBtn setImage:[UIImage imageNamed:@"black"] forState:UIControlStateNormal]; 
  11.        //高亮下image 
  12.        [returnBtn setImage:[UIImage imageNamed:@"grat"] forState:UIControlStateHighlighted]; 
  13.        //正常下title顏色 
  14.        [returnBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
  15.        //高亮下title顏色 
  16.        [returnBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted]; 
  17.        //設(shè)置按鈕位置大小,注意這里位置無效果 
  18.        [returnBtn setFrame:CGRectMake(007020)]; 
  19.        //按鈕內(nèi)部對齊 
  20.        [returnBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft]; 
  21.        //設(shè)置圖片內(nèi)部位置 
  22.        [returnBtn setContentEdgeInsets:UIEdgeInsetsMake(0000)]; 
  23.        //添加點(diǎn)擊事件 
  24.        [returnBtn addTarget:self action:@selector(returnBtnClick) forControlEvents:UIControlEventTouchUpInside]; 
  25.        //當(dāng)視圖推送時隱藏tabbar 
  26.        viewController.hidesBottomBarWhenPushed = YES; 
  27.        //自定義push視圖的leftBarButtonItem 
  28.        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:returnBtn]; 
  29.    } 
  30.    //子控制器通過這個方法推送視圖 
  31.    [super pushViewController:viewController animated:animated]; 

三.添加UIBarButtonItem的類擴(kuò)展UIBarButtonItem+NPBarbutton,創(chuàng)建UIbarbuttonItem類方法

1.UIbarbuttonItem類方法

  1. /** 
  2.  *創(chuàng)建一個UIBarbuttonItem 類方法,這個方法是類方法創(chuàng)建一個按鈕,傳入的參數(shù):image正常顯示的圖片,hightImage高亮情況下顯示的圖片,target用的對象,action點(diǎn)擊的行為。 
  3.  */ 
  4. + (instancetype)itemWithImage:(NSString *)image hightImage:(NSString *)hightImage target:(id)target action:(SEL)action 
  5.     UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 
  6.     [btn setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal]; 
  7.     [btn setBackgroundImage:[UIImage imageNamed:hightImage] forState:UIControlStateNormal]; 
  8.     //btnsize 是北京圖片的大小 
  9.     CGSize btnsize = btn.currentBackgroundImage.size; 
  10.     //設(shè)置btn的frame 
  11.     [btn setFrame:CGRectMake(00, btnsize.width, btnsize.height)]; 
  12.     [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside]; 
  13.     return [[self alloc] initWithCustomView:btn]; 

以上為基礎(chǔ)框架主要實(shí)現(xiàn),還有一些不足,手勢滑動返回沒有寫到。

推廣MarkDown語法鏈接:http://www.jianshu.com/p/7cc9c26e8b7a 作者:大毛集團(tuán)

本文Demo下載地址:http://code.cocoachina.com/view/129999 作者:NiePlus

責(zé)任編輯:倪明 來源: 簡書
相關(guān)推薦

2014-07-10 10:02:01

iOSHome Kit框架

2011-07-07 16:38:21

iOS UITableVie

2011-08-18 11:10:49

Core Plot框架IOS開發(fā)

2011-06-15 16:11:51

UIKitCocoa TouchiOS

2013-07-24 18:22:02

iOS開發(fā)學(xué)習(xí)iOS開源框架和類

2011-05-31 15:41:00

Cocoa TouchCocoaiOS

2012-10-08 12:59:01

iOS 6.0開發(fā)框架功能更新

2011-08-18 11:19:13

IOS開發(fā)Core Plot S

2019-03-01 08:57:47

iOScoobjc協(xié)程

2009-06-26 14:06:08

JSF基礎(chǔ)框架

2013-01-11 15:06:13

iOS開發(fā)移動應(yīng)用iPhone

2012-03-15 15:35:51

iUI框架EclipseiOS Web

2012-05-21 21:34:51

iOS

2016-12-13 10:07:50

JAVA框架搭建

2015-07-27 10:27:32

IOS基礎(chǔ)知識核心動畫

2016-11-04 10:47:27

微信小程序

2012-06-01 11:10:07

iOS基本框架圖示

2019-01-15 14:11:50

Android框架組件化

2022-04-29 09:43:12

IPDKAPI框架DPU/IPU

2014-12-31 14:27:19

ToastLogLSharePrefe
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號