我为我的项目实现了这个自定义 NavigationBar 类:有问题的视频
#import "PTTNavigationBar.h"
@implementation PTTNavigationBar
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
// Overriding drawRect: perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
UIImage *navBarImage = UIIMAGE_NAMED( kNavBarBackGroundImage );
[navBarImage drawInRect:CGRectMake(0, 0, NAVBAR_SIZE.width , NAVBAR_SIZE.height)];
[self setBackgroundColor:[UIColor clearColor]];
}
- (CGSize)sizeThatFits:(CGSize)size {
//[self setTitleVerticalPositionAdjustment:-12 forBarMetrics:UIBarMetricsDefault];
CGRect frame = [UIScreen mainScreen].applicationFrame;
CGSize newSize = CGSizeMake(frame.size.width , NAVBAR_SIZE.height);
[self layoutSubviews];
return newSize;
}
-(void) layoutSubviews
{
[super layoutSubviews];
[self setBackgroundColor:[UIColor clearColor]];
for (UIView *view in self.subviews)
{
CGRect frame = view.frame;
frame.origin.y = 6;
view.frame = frame;
}
}
@end
任何人都可以帮助我吗?谢谢