ios 自定义导航栏背景图片和颜色

{app.params.name}} {app.params.name}} {app.params.name}}

修改导航栏的背景图片,可按照下面的方法操作:

UINavigationBar *navBar = self.navigationController.navigationBar;  
  
#define kSCNavBarImageTag 10  
if ([navBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])  
{  
    //if iOS 5.0 and later  
    [navBar setBackgroundImage:[UIImage imageNamed:@"navbar1.png"] forBarMetrics:UIBarMetricsDefault];  
}  
else  
{  
    UIImageView *imageView = (UIImageView *)[navBar viewWithTag:kSCNavBarImageTag];  
    if (imageView == nil)  
    {  
        imageView = [[UIImageView alloc] initWithImage:  
                     [UIImage imageNamed:@"navbar1.png"]];  
        [imageView setTag:kSCNavBarImageTag];  
        [navBar insertSubview:imageView atIndex:0];  
        [imageView release];  
    }  
} 
修改导航栏的背景色的方法,可按照下面的办法来操作:

navBar.tintColor = [UIColor greenColor]; 


版权声明

davidzhang 创作并维护的 Gowhich 博客采用 创作共用保留署名-非商业-禁止演绎4.0国际许可证。

本文首发于 Gowhich 博客( https://www.gowhich.com ),版权所有,侵权必究。

本文永久链接: https://www.gowhich.com/blog/148

comments powered by Disqus