为UIToolBar设置背景图像

时间:2013-04-01 18:15:42

标签: ios design-patterns crash uitoolbar uiappearance

我见过很多人这样做:

[[UIToolbar appearance] setBackgroundImage:toolBarImage forBarMetrics:UIBarMetricsDefault];

对我来说它不起作用,因为我的应用程序崩溃并说:

-[_UIAppearance setBackgroundImage:]: unrecognized selector sent to instance 0xab8fe80

我已经研究过并发现UIAppearance仅适用于ios 5,但我的模拟器是6.1和我的iPhone。我也使用了可以工作的NavigationBar。

希望你能帮助我:)非常感谢!!

3 个答案:

答案 0 :(得分:3)

这对我有用:

UIImage* toolbarImage = [UIImage imageNamed: @"toolbar_background.png"];
[[UIToolbar appearance] 
    setBackgroundImage: toolbarImage 
    forToolbarPosition: UIToolbarPositionAny
    barMetrics: UIBarMetricsDefault];

答案 1 :(得分:2)

检查一下:

如果UIToolbar包含在ViewController中。

如果UIToolbar包含在ViewController中,则无法更改AppDelegate内的UIToolbar

另见:IOS 5 unrecognized selector send at appearance proxy for setBackgroundImage

阅读所有评论iOS5 changing Background of UIToolbar

答案 2 :(得分:0)

您应该在didfinishlaunchingwithoptions:method

中的app委托实现文件中调用此方法
相关问题