zoukankan      html  css  js  c++  java
  • UINavigationBar添加背景图片

    代码修改如下:

     

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

    {

        _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

     

        _rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]];

        _nav = [[UINavigationController alloc] initWithRootViewController:_rootViewController];

     

        UIImage *backgroundImage = [UIImage imageNamed:@"NaviBackground.png"];

        [self setNavigationBarBackgroundImage:backgroundImage];

     

        [self.window setRootViewController:_nav];

        [self.window makeKeyAndVisible];

     

        returnYES;

    }

     

    - (void)setNavigationBarBackgroundImage:(UIImage *)backgroundImage

    {

        UINavigationBar *navBar = [_nav navigationBar];

        if ([navBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) {

            [navBar setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];

        }

        else {

            UIImageView *imageView = (UIImageView *)[navBar viewWithTag:kSCNavBarImageTag];

            if (imageView == nil) {

                imageView = [[UIImageView alloc] initWithImage:backgroundImage];

                [imageView setTag:kSCNavBarImageTag];

                [navBar insertSubview:imageView atIndex:0];

                [imageView release];

            }

        }

    }

     

    参考:

    Adding a Background Image to UINavigationBar

    An Introduction To UINavigationController

    学习笔记:UINavigationController使用详解

  • 相关阅读:
    excel转换为dta格式
    移动pdf
    豆瓣爬虫
    python给证件照换底色
    OS模块
    决策树参数
    Pandas数据连接
    Sklearn用法
    numpy.loadtxt()用法
    单片机基础(五):定时/计数器的工作原理及工作方式
  • 原文地址:https://www.cnblogs.com/StarMud/p/2796397.html
Copyright © 2011-2022 走看看