首页 > 学院 > 开发设计 > 正文

IOS自定义导航栏背景

2019-11-14 19:51:04
字体:
来源:转载
供稿:网友
//- (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;}

  


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表