gpt4 book ai didi

iphone - navigationBar 设置背景图像 :nil forBarMetrics:UIBarMetricsDefault not working

转载 作者:行者123 更新时间:2023-11-29 03:38:53 24 4
gpt4 key购买 nike

我有一个显示图像缩略图的 UICollectionView。单击时,缩略图会调用另一个 View wallpaperView,以全尺寸显示图像。

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{

// ...insert the usual row number check here

UIViewController *wallpaperView = [QUOWallpaperViewController new];
[self.navigationController pushViewController:wallpaperView animated:YES];
}

(像往常一样,UICollectionView 本身是 UINavigationController 对象的 Root View Controller )

现在,在wallpaperView中,我想隐藏导航栏,并显示我自己的自定义按钮I have already found a solution here .

按照最上面的答案,我将此代码放入wallpaperViewController.m中:

- (void)viewWillAppear:(BOOL)animated
{
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
}

但是,这不起作用。导航栏仍然像往常一样显示。有谁知道为什么会这样吗?

最佳答案

如果您需要在导航上将自己的按钮显示为栏按钮,则无需隐藏导航栏,我已经浏览了您的代码并做了一些修改,只需使用此按钮即可,不要隐藏导航栏。

UIImage* image3 = [UIImage imageNamed:@"mail-48_24.png"]; 
CGRect frameimg = CGRectMake(0, 0, image3.size.width, image3.size.height);
UIButton *someButton = [[UIButton alloc] initWithFrame:frameimg];
[someButton setBackgroundImage:image3 forState:UIControlStateNormal];
[someButton addTarget:self action:@selector(sendmail) forControlEvents:UIControlEventTouchUpInside];
[someButton setShowsTouchWhenHighlighted:YES];

UIBarButtonItem *mailbutton =[[UIBarButtonItem alloc] initWithCustomView:someButton];
self.navigationItem.rightBarButtonItem=mailbutton;
[someButton release];

self.navigationController.navigationBar.translucent = YES; // Setting this slides the view up, underneath the nav bar (otherwise it'll appear black)
const float colorMask[6] = {222, 255, 222, 255, 222, 255};
UIImage *img = [[UIImage alloc] init];
UIImage *maskedImage = [UIImage imageWithCGImage: CGImageCreateWithMaskingColors(img.CGImage, colorMask)];

[self.navigationController.navigationBar setBackgroundImage:maskedImage forBarMetrics:UIBarMetricsDefault];
//remove shadow
[[UINavigationBar appearance] setShadowImage: [[UIImage alloc] init]];

关于iphone - navigationBar 设置背景图像 :nil forBarMetrics:UIBarMetricsDefault not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18756176/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com