本文介绍了在自定义UINavigationBar中绘图,附加到顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UINavigationBar 的子类。它是 barPosition UIBarPositionTopAttached
比我在子类中重写 - (void)drawRect:(CGRect)rect 。作为参数出现的 rect 总是高44像素,我只能在这个矩形内画画。因此,我无法在状态栏上执行绘制,并且它具有默认外观。如果我评论 -drawRect out,它看起来与预期的一样,导航栏和状态栏看起来整体并且高度为64像素。有没有办法在 UINavigationBar 的子类中覆盖 -drawRect:来实现这种效果?

I have a subclass of UINavigationBar. It's barPosition is UIBarPositionTopAttached.Than I override -(void)drawRect:(CGRect)rect in my subclass. The rect, that comes as parameter, has always 44 px height, and I can draw only inside this rect. So, I can't perform drawing over the status bar and it has default look. If I comment -drawRect out, than it looks as expected, navigation bar and status bar look as a whole and have 64 px height. Is there a way to achieve this effect with having overrided -drawRect: in subclass of UINavigationBar?

推荐答案

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

I had a the issue of a custom UINavigationBAr with a background image which would not appear under the translucent Status Bar on iOS 7 when I was adding the image in drawRect.

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

After moving the background image to the ViewControllers viewDidLoad Method, the background image then appeared under the Status Bar

-(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 …

希望这有助于

这篇关于在自定义UINavigationBar中绘图,附加到顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 20:55