【问题标题】:How to add an image in the navigation bar如何在导航栏中添加图像
【发布时间】:2013-05-24 06:53:02
【问题描述】:

我想在导航栏中添加一张图片。它应该贯穿我的应用程序。它应该被添加到所有导航控制器中。

任何帮助将不胜感激。

【问题讨论】:

标签: iphone ios objective-c uiimageview uinavigationbar


【解决方案1】:

试试这个,

UINavigationBar *navBar = self.navigationController.navigationBar;
UIImage *image = [UIImage imageNamed:@"image.png"];
[navBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

【讨论】:

    【解决方案2】:

    您可以使用以下代码添加图像..

    UIImage *image = [UIImage imageNamed: @"yourImageName.png"];
    UIImageView *imgView = [[UIImageView alloc] initWithImage: image];
    self.navigationItem.titleView = imgView;
    

    【讨论】:

      【解决方案3】:
      if ([[UINavigationBar class] respondsToSelector:@selector(appearance)])
          {
              [[UINavigationBar appearance] setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageName ofType:@"png"]] forBarMetrics:UIBarMetricsDefault];
              [[UINavigationBar appearance] setTitleTextAttributes:
               [NSDictionary dictionaryWithObjectsAndKeys:
                [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
                UITextAttributeTextColor,
                [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],
                UITextAttributeTextShadowColor,
                [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                UITextAttributeTextShadowOffset,
                [UIFont fontWithName:@"HelveticaNeue-Bold" size:18.0],
                UITextAttributeFont,
                nil]];
          }
      

      将其放入您的 Appdelegate.m

      【讨论】:

        【解决方案4】:

        你使用这个代码:

         [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"Image.png"] forBarMetrics:UIBarMetricsDefault];
        

        【讨论】:

          【解决方案5】:

          我是一个理想的,因为我有这样的问题,所以你可以试试我的方法,ok!!

          首先,您创建一个导航控制器,然后将其显示在窗口中

          UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:YourView];

          下一步:您创建一个具有图像属性的对象 Uiimageview 与您想要添加导航栏的图像和框架 ptoperty 是您想要的位置

          UIImageView *imgView=[UIImageView alloc] initWithImage:[UIImage imageNamed:@"YourImagename"]; imgView.Frame=CGrectmake();

          最后一步:在导航栏中添加对象 imgView 作为子视图

          [nav.navigationBar addSubview:imgView];
          

          完成!!!!!!!!!!

          【讨论】:

            猜你喜欢
            • 2018-06-23
            • 1970-01-01
            • 2013-11-28
            • 2010-12-05
            • 2018-02-07
            • 1970-01-01
            • 2015-03-28
            相关资源
            最近更新 更多