Drawing in custom UINavigationBar, attached to top

戏子无情 提交于 2019-12-11 10:44:38

问题


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?


回答1:


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.

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 …

Hopefully this helps



来源:https://stackoverflow.com/questions/19523432/drawing-in-custom-uinavigationbar-attached-to-top

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!