4

我正在制作一个与 iOS7 兼容的应用程序,但我遇到了 UINavigationBar 的问题,这让我抓狂:

我想让我的导航栏完全透明,没有任何模糊或背景图片,但包含和显示导航项按钮。

在 iOS6 中,我曾经这样做过:

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

但它不再适用于iOS7。

有什么建议么 ?

4

2 回答 2

2

也许会回答你的问题?如果您选择视图控制器,然后取消选中“在顶栏下延伸边缘”旁边的框,则背景图像不会在其下方流血。

于 2013-09-19T23:31:33.180 回答
0
@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
于 2013-10-08T09:18:48.680 回答