如何将附加的阴影添加到uinavigationbar和uitoolbar [英] how can I add attached drop shadows to uinavigationbar and uitoolbar

查看:104
本文介绍了如何将附加的阴影添加到uinavigationbar和uitoolbar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用UINavigationBar和UIToolbar的自定义图像的应用程序,这很好,但是它们还需要在导航栏下方和工具栏上方的阴影,它总是位于所有其他视图控制器之上。我不能简单地制作包含阴影的背景图像,因为这对我的tableviews不起作用。当我将导航栏和工具栏设置为隐藏(动画)时,我还需要阴影动画。

I'm working on an app that uses a custom image for UINavigationBar and UIToolbar, which is fine, but they also need a drop shadow below the nav bar and above the toolbar, which would always rest above all other view controllers. I cannot simply make background images which include the shadows as this would not work well with my tableviews. I also need the shadows animate away when I set nav bar and tool bar to hidden (animated).

我查看了网上的Stack Overflow和其他来源,并且已经完成了所提出的解决方案,但我无法成功地将UINavigationBar,UIToolbar甚至UINavigationController子类化,以提供我所追求的结果。

I've looked through Stack Overflow and other sources on the net, and have worked through the proposed solutions but I cannot successfully subclass UINavigationBar, UIToolbar or even UINavigationController to provide the results I am after.

非常感谢可以提供的任何帮助。谢谢:)

Would appreciate any help that could be offered. Thanks :)

推荐答案

最后我决定只使用背景png图像和阴影,并将它们应用于子类UINavigationBar和UIToolbar实现了drawRect方法(用于背景图像)和sizeThatFits方法来调整导航栏的大小。这是最终产品(按钮隐藏栏):

In the end I decided to just use background png images with the shadows, and apply them with a subclass for UINavigationBar and UIToolbar which implemented the drawRect method (for the background image) and the sizeThatFits method to resize the navigation bar. Here is the final product (the button hides the bars):

以下是我在每个子类中实现的方法:

Here are the methods I implemented in each subclass:

 - (void)drawRect:(CGRect)rect {
   UIImage *image = [[UIImage imageNamed:@"bargloss-withshadow.png"] retain];
   [image drawInRect:rect];
   [image release];
}


- (CGSize)sizeThatFits:(CGSize)size {
    CGSize newSize = CGSizeMake(320,60);
    return newSize;
}

请注意,我还在IB中制作了Black Translucent栏,以便内容在他们之下流动。

Please note that I also made the bars Black Translucent in IB so that the content flowed under them.

这篇关于如何将附加的阴影添加到uinavigationbar和uitoolbar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆