簡體   English   中英

如何在iOS7上使UINavigationBar完全透明?

[英]How can I make my UINavigationBar totally transparent on iOS7?

我正在開發與iOS7兼容的應用程序,並且遇到UINavigationBar的問題,這使我發瘋:

我想使我的navigationBar完全透明,沒有任何模糊或backgroundPicture,但包含並顯示navigationItem按鈕。

在iOS6中,我通常是這樣進行的:

UIImage *maskedImage = [UIImage imageNamed:@"transparent_image.png"]
[navigationBar setBackgroundImage:maskedImage forBarMetrics:UIBarMetricsDefault];

但它在iOS7上不再起作用。

有什么建議么 ?

也許會回答您的問題? 如果您選擇視圖控制器,然后取消選中“在頂部欄下方擴展邊緣”旁邊的框,則背景圖像將不會在其下方流血。

@implementation MyCustomNavigationBar

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self setup];
    }
    return self;
}

- (void)setup {
    [self setupBackground];
}

- (void)setupBackground {
    self.backgroundColor = [UIColor clearColor];
    self.tintColor = [UIColor clearColor];

    // make navigation bar overlap the content
    self.translucent = YES; 
    self.opaque = NO;

    // remove the default background image by replacing it with a clear image
    [self setBackgroundImage:[self.class maskedImage] forBarMetrics:UIBarMetricsDefault];

    // remove defualt bottom shadow
    [self setShadowImage: [UIImage new]]; 
}

+ (UIImage *)maskedImage {
    const float colorMask[6] = {222, 255, 222, 255, 222, 255};
    UIImage *img = [UIImage imageNamed:@"nav-white-pixel-bg.jpg"];
    return [UIImage imageWithCGImage: CGImageCreateWithMaskingColors(img.CGImage, colorMask)];
}

@end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM