【问题标题】:navigation bar image hiding custom navigation bar button导航栏图像隐藏自定义导航栏按钮
【发布时间】:2017-07-02 10:11:24
【问题描述】:

我可以为导航栏提供图像,还可以更改导航栏按钮项的图像。出于某种原因,我猜导航栏图像与导航栏按钮图像重叠。当我单击左侧的导航栏图像时,导航栏按钮正常工作,但它没有显示在导航栏图像上。这是代码;

UIImage *imagebar = [UIImage imageNamed: @"schedule-strip.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: imagebar];
imageView.frame = CGRectMake(0, 0, 190, 44);
imageView.contentMode = UIViewContentModeScaleAspectFill;
self.navigationItem.titleView = imageView;


UIImage* image = [UIImage imageNamed:@"back-icon.png"];
CGRect frame = CGRectMake(0, 0, image.size.width, image.size.height);
UIButton* someButton = [[UIButton alloc] initWithFrame:frame];
[someButton setBackgroundImage:image forState:UIControlStateNormal];
[someButton setShowsTouchWhenHighlighted:YES];
[someButton addTarget:self action:@selector(backToMore) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem* someBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:someButton];
[self.navigationItem setLeftBarButtonItem:someBarButtonItem];

[someBarButtonItem release];
[someButton release]; 

帮帮我。

【问题讨论】:

  • 试试 imageView.clipToBounds = YES;

标签: iphone ios uinavigationitem navigationcontroller


【解决方案1】:

使用代码 [imageView addsubView someButton];

我希望现在您会看到该按钮。实际上,您正在将左栏按钮项目添加到默认导航栏,并且当您创建某个按钮时,它不会被添加到与导航栏重叠的 imageview 上。因此,通过单击该区域它正在工作,但按钮不可见。

【讨论】:

    【解决方案2】:
    - (void)drawRect:(CGRect)rect {
        UIImage *image = [UIImage imageNamed: @"TopBg.png"];
        [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    }
    

    扩展@interface MyToolBar : UIToolbar 并创建 MyToolBar 的对象。之后为导航栏制作自定义按钮。享受并喜欢它

    【讨论】:

      【解决方案3】:

      Ketan 你检查过图片吗?您的项目中是否存在图像? 为什么要为导航栏标题使用框架和内容模式属性? 愿此链接对您有所帮助

      http://iosdevelopertips.com/user-interface/ios-5-customize-uinavigationbar-and-uibarbuttonitem-with-appearance-api.html

      【讨论】:

      • 您提到的项目中使用的图像只有一个垂直条(一条线),我有完整的图像,提供给导航栏,但唯一的问题是导航栏按钮没有显示。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多