-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setnavigation];
}
{
[super viewWillAppear:animated];
[self setnavigation];
}
用presentViewController 模态出视图时,需要在viewWillAppear里设置navigationController,否则会出现先加载页面,后改变navigation属性,但是改变延迟,显示页面的时候,并不会设置后的效果
附:
#pragma mark -
设置
navigation
-( void )setnavigation
{
[ self . navigationController . navigationBar setBarStyle : UIBarStyleBlack ]; // 执行状态栏白色
self . navigationController . navigationBar . translucent = NO ; // 设置不半透明
// UIBarButtonItem * rightBtn = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@" 个人中心 "]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(clickRightBtn:)];
// self.navigationItem.rightBarButtonItem = rightBtn;
// 设置背景颜色
if ( IS_IOS7 ) {
self . navigationController . navigationBar . barTintColor = [ UIColor colorWithRed : 45.0 / 255.0 green : 45.0 / 255.0 blue : 45.0 / 255.0 alpha : 1 ];
self . navigationController . navigationBar . tintColor = [ UIColor whiteColor ];
// 设置标题字体和颜色
NSDictionary *dic1 = [ NSDictionary dictionaryWithObjectsAndKeys :[ UIColor whiteColor ], NSForegroundColorAttributeName ,[ UIFont fontWithName : @"TrebuchetMS-Bold" size : 20 ], NSFontAttributeName , nil ];
[ self . navigationController . navigationBar setTitleTextAttributes :dic1];
[[ UINavigationBar appearance ] setTitleTextAttributes :dic1];
}
// 添加返回按钮
UIBarButtonItem * leftBtn = [[ UIBarButtonItem alloc ] initWithTitle : @" 取消 " style : UIBarButtonItemStylePlain target : self action : @selector (doQuxiao)];
self . navigationItem . leftBarButtonItem = leftBtn;
}
-( void )doQuxiao
{
[ self dismissViewControllerAnimated : YES completion : nil ];
}
-( void )setnavigation
{
[ self . navigationController . navigationBar setBarStyle : UIBarStyleBlack ]; // 执行状态栏白色
self . navigationController . navigationBar . translucent = NO ; // 设置不半透明
// UIBarButtonItem * rightBtn = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@" 个人中心 "]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(clickRightBtn:)];
// self.navigationItem.rightBarButtonItem = rightBtn;
// 设置背景颜色
if ( IS_IOS7 ) {
self . navigationController . navigationBar . barTintColor = [ UIColor colorWithRed : 45.0 / 255.0 green : 45.0 / 255.0 blue : 45.0 / 255.0 alpha : 1 ];
self . navigationController . navigationBar . tintColor = [ UIColor whiteColor ];
// 设置标题字体和颜色
NSDictionary *dic1 = [ NSDictionary dictionaryWithObjectsAndKeys :[ UIColor whiteColor ], NSForegroundColorAttributeName ,[ UIFont fontWithName : @"TrebuchetMS-Bold" size : 20 ], NSFontAttributeName , nil ];
[ self . navigationController . navigationBar setTitleTextAttributes :dic1];
[[ UINavigationBar appearance ] setTitleTextAttributes :dic1];
}
// 添加返回按钮
UIBarButtonItem * leftBtn = [[ UIBarButtonItem alloc ] initWithTitle : @" 取消 " style : UIBarButtonItemStylePlain target : self action : @selector (doQuxiao)];
self . navigationItem . leftBarButtonItem = leftBtn;
}
-( void )doQuxiao
{
[ self dismissViewControllerAnimated : YES completion : nil ];
}