1. 程式人生 > >iOS導航欄顏色

iOS導航欄顏色

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //通過設定BackgroundImage來設定導航的背景
    //設定背景為透明
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
    //還原為系統預設
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:nil];
}