UINavigationbar의 그림자 만들기를 알고 싶습니다. 그림자를 사용하여 사용자 정의 탐색 모음 배경을 만들려고했으나 그림자가 배경보기를 덮습니다.UINavigationBar 그림자 생성 방법
@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
UIImage *image = [[UIImage imageNamed:@"titleBar.png"] retain];;
[image drawInRect:rect];
[image release];
}
- (CGSize)sizeThatFits:(CGSize)size {
CGSize newSize = CGSizeMake(320,50);
return newSize;
}
@end
I also tried on following solution: http://www.travisboudreaux.com/adding-a-drop-shadow-to-a-uinavigationbar:
@interface UINavigationBar (dropshadow)
-(void) applyDefaultStyle;
@end
@implementation UINavigationBar (dropshadow)
-(void)willMoveToWindow:(UIWindow *)newWindow{
[self applyDefaultStyle];
}
- (void)applyDefaultStyle {
// add the drop shadow
self.layer.shadowColor = [[UIColor blackColor] CGColor];
self.layer.shadowOffset = CGSizeMake(0.0, 3.0);
self.layer.shadowOpacity = 0.25;
}
@end
네비게이션 바 버튼에는 그림자가 있지만 탐색 바는 표시되지 않습니다.
최종 솔루션 : 다음은 UINavigationBar의 그림자를 만드는 방법입니다. 내 코드의 누락 된 링크를 지적 MusiGenesis에 대한 큰 감사 :
#import <QuartzCore/QuartzCore.h>
@interface UINavigationBar (CustomImage)
-(void) applyDefaultStyle;
@end
//Override For Custom Navigation Bar
@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"titleBar.png"];
[image drawInRect:CGRectMake(0, 0, 320, 44)];
}
-(void)willMoveToWindow:(UIWindow *)newWindow{
[super willMoveToWindow:newWindow];
[self applyDefaultStyle];
}
- (void)applyDefaultStyle {
// add the drop shadow
self.layer.shadowColor = [[UIColor blackColor] CGColor];
self.layer.shadowOffset = CGSizeMake(0.0, 3);
self.layer.shadowOpacity = 0.25;
self.layer.masksToBounds = NO;
self.layer.shouldRasterize = YES;
}
@end
** quartzcore을 가져 기억 아니면 오류가 발생합니다. applyDefaultStyle
에서
빠른 참고로, 내가 호출 생각'[슈퍼 willMoveToWindow : ..] '카테고리 그것이 – Sam
Ah..yes에서 중복됩니다. 수정했습니다. 감사. – TonyTakeshi
이것이 나에게 많은 도움이되었습니다 - 감사합니다! – boz