Vorrei un file completamente trasparente UIToolbare / o UINavigationBar. Ho provato i vari incantesimi suggeriti per pre e post iOS 5 ma nessuno sembra funzionare più.
Come potrebbe essere realizzato in iOS 7?
Vorrei un file completamente trasparente UIToolbare / o UINavigationBar. Ho provato i vari incantesimi suggeriti per pre e post iOS 5 ma nessuno sembra funzionare più.
Come potrebbe essere realizzato in iOS 7?
Risposte:
UIToolbarself.toolbar.setBackgroundImage(UIImage(),
forToolbarPosition: .any,
barMetrics: .default)
self.toolbar.setShadowImage(UIImage(), forToolbarPosition: .any)
UINavigationBarself.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationBar.shadowImage = UIImage()
self.navigationBar.isTranslucent = true
UIToolbarself.toolbar.setBackgroundImage(UIImage(),
forToolbarPosition: UIBarPosition.Any,
barMetrics: UIBarMetrics.Default)
self.toolbar.setShadowImage(UIImage(),
forToolbarPosition: UIBarPosition.Any)
UINavigationBarself.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
self.navigationBar.shadowImage = UIImage()
self.navigationBar.translucent = true
UIToolbar[self.toolbar setBackgroundImage:[UIImage new]
forToolbarPosition:UIBarPositionAny
barMetrics:UIBarMetricsDefault];
[self.toolbar setShadowImage:[UIImage new]
forToolbarPosition:UIBarPositionAny];
UINavigationBar[self.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationBar.shadowImage = [UIImage new];
self.navigationBar.translucent = YES;
L'impostazione translucentsu YESsulla barra di navigazione fa il trucco, a causa di un comportamento discusso nella UINavigationBardocumentazione. Riporto qui il frammento rilevante:
Se si imposta questa proprietà
YESsu una barra di navigazione con un'immagine di sfondo personalizzata opaca, la barra di navigazione applicherà un'opacità di sistema inferiore a 1.0 all'immagine.

iOS 7simulatore
Se vuoi farlo attraverso l'intera app dovresti usare il proxy UIAppearance (iOS5 +):
UINavigationBar *navigationBarAppearance = [UINavigationBar appearance];
navigationBarAppearance.backgroundColor = [UIColor clearColor];
[navigationBarAppearance setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
navigationBarAppearance.shadowImage = [[UIImage alloc] init];
Articolo: http://nshipster.com/uiappearance/
UINavigationControllersottoclassi specifiche , ovvero quelle a cui si desidera applicare questo comportamento.
@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