美文网首页
iOS OC 设置透明navigationBar

iOS OC 设置透明navigationBar

作者: Wougle | 来源:发表于2017-03-22 21:34 被阅读0次

    最近做项目遇到一种需求: 需要将navigationBar设置为透明。效果如下:

    我的做法是先隐藏原来的navigation:

    self.navigationController.navigationBarHidden = YES;

    然后添加一个navigationBar:

    //添加一个UINavigationBar

    CGRect screenRect = [[UIScreen mainScreen] bounds];

    imageNavigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, screenRect.size.width, 64)];

    [self.view addSubview: imageNavigationBar];

    //往imageNavigationBar上设置背景图

    UIImage *barImage = [UIImage imageNamed:@"bg_home_nav"];

    UIImage *scaleBarImage = [[UIImage alloc] init];

    scaleBarImage = [scaleBarImage image:barImage byScalingToSize:CGSizeMake(SCREEN_WIDTH, 64)];

    [imageNavigationBar setBackgroundImage:scaleBarImage forBarMetrics:UIBarMetricsDefault];

    imageNavigationBar.shadowImage = [UIImage new];

    imageNavigationBar.translucent = NO;

    gotta

    相关文章

      网友评论

          本文标题:iOS OC 设置透明navigationBar

          本文链接:https://www.haomeiwen.com/subject/ajdanttx.html