【问题标题】:Add UIImageView on UINavigationBar in iphone在 iphone 的 UINavigationBar 上添加 UIImageView
【发布时间】:2011-10-04 13:18:00
【问题描述】:

我正在 iphone 中开发一个应用程序。我必须在我的视图或 UINavigation 栏上添加图像。我的条件是图像将部分添加到导航栏,部分添加到视图中。

我已将它作为条形按钮项添加到标题视图中,但它的高度受条形高度的限制。我需要它放在导航栏下方。

如何实现?

提前致谢。

【问题讨论】:

    标签: iphone image navigation uinavigationbar


    【解决方案1】:

    您可以将图像视图添加为导航栏的子视图,如下所示:

    [myNavBar insertSubview:myImageView atIndex:0]; 
    

    【讨论】:

    • 对不起,我在 insertSubview 之前发布了一个版本。编辑它,这样我就可以给你投票了
    【解决方案2】:

    子类 UiNavigatonbar 类:)

    【讨论】:

      【解决方案3】:
          UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourImageName"]];
          imageView.frame = CGRectMake(100, 0, 200, 80);
          [self.parentViewController.view.window addSubview:imageView];
      
          [imageView release];
      

      【讨论】:

      • 感谢代码,它在纵向模式下工作正常,但我必须在横向模式下实现它,请帮助我。
      【解决方案4】:
      #define kWidth [UIScreen mainScreen].bounds.size.width
      
      In the <UIViewController.m>:
      
      - (void)viewDidLoad
      {
          UIImageView *titleImageView = [[UIImageView alloc] initWithFrame:CGRectMake(kWidth-10, 0, 20, 20)];
          titleImageView.image = [UIImage imageNamed:@"The Image Name"];
      
          titleImageView.contentMode = UIViewContentModeScaleAspectFit;
      
          self.navigationItem.titleView = titleImageView;
      }
      

      对我有用,对你有用吗?祝你好运!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-22
        • 2017-03-17
        • 2022-01-07
        • 2023-04-01
        • 1970-01-01
        相关资源
        最近更新 更多