在自定义的UINavigationBar中绘制,附在顶部

我有一个UINavigationBar的子类。 它的barPositionUIBarPositionTopAttached 。 比我重写-(void)drawRect:(CGRect)rect在我的子类。 作为参数的rect总是有44像素的高度,而且我只能在这个矩形内部绘制。 所以,我不能执行绘图状态栏,它有默认的外观。 如果我评论 – -drawRect ,看起来如预期,导航栏和状态栏看起来整体,并有64像素的高度。 有没有一种方法来实现这个效果与-drawRect:UINavigationBar子类?

我有一个自定义的UINavigationBAr的背景图像的问题,当我在drawRect中添加图像时,不会出现在iOS 7的半透明状态栏下。

将背景图像移动到ViewControllers viewDidLoad方法后,背景图像出现在状态栏下

 -(void)viewDidLoad { if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad) { UIImage *image = [UIImage imageNamed:@"nav-bg-ipad.png"]; [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault]; }else{ UIImage *image = [UIImage imageNamed:@"nav-bg-iphone.png"]; [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault]; } // do your other stuff now … 

希望这有助于