Muốn biết tạo bóng đổ cho thanh UINavigation. Tôi đã cố gắng tạo nền thanh điều hướng tùy chỉnh với bóng đổ, nhưng bóng đổ bao phủ chế độ xem nền.Cách tạo bóng thả 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
Nút này hiển thị bóng thả cho nút thanh điều hướng của tôi, nhưng không có thanh điều hướng.
Giải pháp cuối cùng: Đây là cách tôi tạo bóng thả cho UINavigationBar. Cảm ơn bạn đã gửi đến MusiGenesis để chỉ ra liên kết còn thiếu của mã của tôi:
#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
** Hãy nhớ nhập thạch anh hoặc lỗi sẽ ném lỗi.
Nhanh chóng, tôi nghĩ gọi '[super willMoveToWindow: ..]' là dư thừa trong một danh mục – Sam
Ah..có vẻ như vậy. Đã sửa đổi nó. Cảm ơn. – TonyTakeshi
điều này đã giúp tôi rất nhiều - cảm ơn! – boz