微博(二)自定义导航栏UINavigationControlle

2016-01-12  本文已影响361人  破夕_____________

自定义导航栏,方便push(到一个新的页面的时候隐藏底栏)

具体代码如下

-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{ if (self.viewControllers.count > 0) { viewController.hidesBottomBarWhenPushed = YES; } [super pushViewController:viewController animated:animated]; }

自定义导航栏的主题,样式,文字样式,同样是在UINavigationController控制器里面

代码如下


/**

+(void)initialize{

[self settingTheme];


[self settingBarButtonItemTheme];

}
//设置导航栏的主题

+(void)settingTheme{
/**
 *  第一次使用这个类的时候会调用(只会调用一次)
 */
 //    1.取出appearance对象
UINavigationBar *navBar = [UINavigationBar appearance];

 //   2.设置背景 ios6
//    [navBar setBackgroundImage:[UIImage imageNamed:@"navigationbar_background"] forBarMetrics:UIBarMetricsDefault];
//    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];

/**这ios7以后新的设置方法
 *  UIKIT_EXTERN NSString *const UITextAttributeFont NS_DEPRECATED_IOS(5_0, 7_0, "Use NSFontAttributeName") __TVOS_PROHIBITED;
 // Key to the text color in the text attributes dictionary. A UIColor instance is expected.
 UIKIT_EXTERN NSString *const UITextAttributeTextColor NS_DEPRECATED_IOS(5_0, 7_0, "Use NSForegroundColorAttributeName") __TVOS_PROHIBITED;
 // Key to the text shadow color in the text attributes dictionary.  A UIColor instance is expected.
 UIKIT_EXTERN NSString *const UITextAttributeTextShadowColor NS_DEPRECATED_IOS(5_0, 7_0, "Use NSShadowAttributeName with an NSShadow instance as the value") __TVOS_PROHIBITED;
 // Key to the offset used for the text shadow in the text attributes dictionary. An NSValue instance wrapping a UIOffset struct is expected.
 UIKIT_EXTERN NSString *const UITextAttributeTextShadowOffset NS_DEPRECATED_IOS(5_0, 7_0, "Use NSShadowAttributeName with an NSShadow instance as the value") __TVOS_PROHIBITED;
 */
//设置颜色
textAttrs[NSForegroundColorAttributeName] = [UIColor blackColor];
//    设置阴影
textAttrs[NSShadowAttributeName] = nil;
textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:20];

[navBar setTitleTextAttributes:textAttrs];

}

/**

上一篇 下一篇

猜你喜欢

热点阅读