代碼搭建記事本架構(二)

來源:互聯網
上載者:User

標籤:

主題設定,初始化的代碼,通過執行這些代碼來設定對應的navigation和barbutton的屬性

/** *  只執行一次的代碼 */+(void)initialize{    //設定nav對應的屬性.    [self setNavigationBarTheme];    //設定barbutton對應的屬性.    [self setBarButtonTheme ];}

對應屬性的設定

+(void)setBarButtonTheme{    //    UIBarButtonItem *appearence = [UIBarButtonItem appearance];        NSMutableDictionary *textAttrs =[[NSMutableDictionary alloc]init];    textAttrs[NSForegroundColorAttributeName] = [UIColor orangeColor];    textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:15];    [appearence setTitleTextAttributes:textAttrs forState:UIControlStateNormal];        NSMutableDictionary *highTextAttrs =[[NSMutableDictionary alloc]init];    highTextAttrs[NSForegroundColorAttributeName] = [UIColor redColor];    highTextAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:15];    [appearence setTitleTextAttributes:highTextAttrs forState:UIControlStateHighlighted];        NSMutableDictionary *disableTextAttrs =[[NSMutableDictionary alloc]init];    disableTextAttrs[NSForegroundColorAttributeName] = [UIColor grayColor];    disableTextAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:15];    [appearence setTitleTextAttributes:disableTextAttrs forState:UIControlStateDisabled];        //為了讓按鈕的背景消失,可以設定一張完全透明的背景圖片    [appearence setBackgroundImage:[UIImage imageNamed:@"navigationbar_button_background"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];}+(void)setNavigationBarTheme{    UINavigationBar *appearence  = [UINavigationBar appearance];        NSMutableDictionary *textAttrs= [NSMutableDictionary dictionary];    textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:20];    textAttrs[NSForegroundColorAttributeName] = [UIColor blackColor];    [appearence setTitleTextAttributes:textAttrs];}

定義為類方法,容易調用。

 

最重要的方法還是重載的push方法

-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{    if (self.viewControllers.count>0) {   //如果push進來的不是棧底控制器的話        viewController.hidesBottomBarWhenPushed = YES;        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImage:@"navigationbar_back" highImage:@"navigationbar_back_highlighted" target:self action:@selector(back)];        viewController.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithImage:@"navigationbar_more" highImage:@"navigationbar_more_highlighted" target:self action:@selector(more)];    }    [super pushViewController:viewController animated:YES];}

push中的來設定對應的屬性,包括對應的背景和高亮背景點擊時間對應的響應函數。

 

設定對應的按鈕點擊的響應內容。

-(void)more
{
    [self popToRootViewControllerAnimated:YES];
}
-(void)back
{
    [self popViewControllerAnimated:YES];
}

代碼搭建記事本架構(二)

相關文章

聯繫我們

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