导航栏背景隐藏了右键,无法在下次查看时将其删除
我正在使用下面的类别以编程方式将导航栏背景更改为我的应用程序。它工作正常,但我看不到我在导航栏中添加的右侧按钮。该按钮似乎隐藏,因为点击右侧导航栏仍然会触发连接到导航栏右侧按钮的操作。另外,如何删除使用给定类别方法添加的导航背景?
UINavigationBar+CustomImage.h
#import <Foundation/Foundation.h>
@interface UINavigationBar (CustomImage)
- (void)setBackgroundImage:(UIImage *)image;
- (void)clearBackgroundImage;
UINavigationBar+CustomImage.m
#import "UINavigationBar+CustomImage.h"
@implementation UINavigationBar (CustomImage)
{
if(image==nil) return;
UIImageView *image_view = [[UIImageView alloc] initWithImage:image];
image_view.frame = CGRectMake(0,0,320,44);
[self addSubview:image_view];
}
- (void)clearBackgroundImage
{
NSSArray *subviews = [self subviews];
for(int i=0;i<[subviews count];i++)
{
if([[subviews objectAtIndex:i] isMemberOfClass:[UIImageView class]])
{
[[subviews objectAtIndex:i] removeFromSuperview];
}
}
}
在我的视图控制器中它的调用方式如下:
[[self.navigationController navigationBar] performSelectorInBackground:@selector(setBackgroundImage:) withObject:[UIImage imageNamed:@"header-background.png"]];
感谢您的帮助,
Stephane
I'm using the category below to programmatically change the navigation bar background into my app. It works fine but I cannot see the right button I added in the nav bar. The button seems hidden as tapping on right side nav bar still trigger the action connected to the nav bar right button. Also, how do I remove the navigation background that was added with the given category method ?
UINavigationBar+CustomImage.h
#import <Foundation/Foundation.h>
@interface UINavigationBar (CustomImage)
- (void)setBackgroundImage:(UIImage *)image;
- (void)clearBackgroundImage;
UINavigationBar+CustomImage.m
#import "UINavigationBar+CustomImage.h"
@implementation UINavigationBar (CustomImage)
{
if(image==nil) return;
UIImageView *image_view = [[UIImageView alloc] initWithImage:image];
image_view.frame = CGRectMake(0,0,320,44);
[self addSubview:image_view];
}
- (void)clearBackgroundImage
{
NSSArray *subviews = [self subviews];
for(int i=0;i<[subviews count];i++)
{
if([[subviews objectAtIndex:i] isMemberOfClass:[UIImageView class]])
{
[[subviews objectAtIndex:i] removeFromSuperview];
}
}
}
And in my view controller it's called like this:
[[self.navigationController navigationBar] performSelectorInBackground:@selector(setBackgroundImage:) withObject:[UIImage imageNamed:@"header-background.png"]];
Thanks for helping,
Stephane
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将您的视图发送到后面:
将其放置在特定的 z-index:
或另一个视图下方:
或另一个视图上方:
try sending your view to the back:
placing it at a specific z-index:
or below another view:
or above another view: