码迷,mamicode.com
首页 > 移动开发 > 详细

IOS 自定义导航栏背景

时间:2014-11-20 01:23:21      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:blog   io   ar   os   sp   for   on   div   log   

//- (void)setBackgroundImage:(UIImage *)backgroundImage forBarMetrics:(UIBarMetrics)barMetrics NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
-(id)init
{
    self=[super init];
    if(self)
    {
        UINavigationBar *navBar=[self navigationBar];
        if([navBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
        {
//如果是IOS5
            [[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:@"NavBar.png"] forBarMetrics:UIBarMetricsDefault];
        }
        else
        {
            UIImageView *imgView=(UIImageView*)[navBar viewWithTag:NAVBARIMAGETAG];
            if(imgView==nil)
            {
                imgView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0,navBar.frame.size.width, navBar.frame.size.height)];
                [imgView setImage:[UIImage imageNamed:@"NavBar.png"]];
                [navBar insertSubview:imgView atIndex:0];
                [imgView release];
            }
        }
    }
    return self;
}

  

IOS 自定义导航栏背景

标签:blog   io   ar   os   sp   for   on   div   log   

原文地址:http://www.cnblogs.com/lgphp/p/4109556.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!