外观代理 - setShadowImage替代iOS 5? [英] Appearance proxy - setShadowImage alternative for iOS 5?
本文介绍了外观代理 - setShadowImage替代iOS 5?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我使用这个代码来设置我的navbar的阴影图像:
Hello I'm using this code to set the shadow image of my navbar:
if ([self.navigationController.navigationBar respondsToSelector:@selector(shadowImage)]) {
[[UINavigationBar appearance] setShadowImage:[UIImage imageNamed:@"nav-bar-shadow"]];
[[UIToolbar appearance] setShadowImage:[UIImage imageNamed:@"tool-bar-shadow"] forToolbarPosition:UIToolbarPositionAny];
}
但是看起来这只是iOS 6肯定 - 我找不到这方面的文档)。它在iOS 5上不起作用。
However it seems this is iOS 6 only (though I can't say for sure - I can't find documentation about this anywhere). It doesn't work on iOS 5.
有没有其他选择 - 在navbar下全局设置图像?
Is there some kind of alternative - globally setting an image under the navbar? I thought of custom UIView, but how to do this globally?
推荐答案
您可以:
- 添加一个包含阴影图像的子视图到
viewController.view
- 将包含阴影图像的子视图添加到
[[UIApplication sharedApplication] keyWindow]
,这将在您的窗口上全局添加图像。但是,它可以得到一点丑陋。 - 您可以子类化
UINavigationBar
,在子视图中做一些魔术,然后通过[[UINavigationController alloc] initWithNavigationBarClass:[YourNavBarSubclass class] toolbarClass:[UIToolbar class]]
- Add a subview containing the shadow image to your
viewController.view
- Add a subview containing the shadow image to your
[[UIApplication sharedApplication] keyWindow]
, which will add the image globally on your window. However, it can get a little bit ugly e.g. when displaying a modal view controller. - You can subclass
UINavigationBar
, do some magic with subviews in there and then initialize your navigationController via[[UINavigationController alloc] initWithNavigationBarClass:[YourNavBarSubclass class] toolbarClass:[UIToolbar class]]
这篇关于外观代理 - setShadowImage替代iOS 5?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文