使用iOS5.1设置UIToolbar背景图像 [英] Setting UIToolbar background image with iOS5.1

查看:101
本文介绍了使用iOS5.1设置UIToolbar背景图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码将图像"Sample"设置为UIToolbar的背景色

I used the following code to set the image "Sample" as a background color of my UIToolbar

self.toolbar.layer.contents = (id)[UIImage imageNamed:@"Sample.png"].CGImage;

但是,上述方法似乎不适用于iOS5.1,并且出现了UIToolbar的默认背景色.我在iOS4中的这一行没有任何问题.

But it seems the above one does not works with iOS5.1 and the default background color of UIToolbar appeared. I doesn't have any problem with this line in iOS4.

我错过了什么吗?请告诉我原因.

Am I missing something? Please suggest me the reason..

谢谢

推荐答案

// Create resizable images
UIImage *gradientImage44 = [[UIImage imageNamed:@"imageName.png"] 
                            resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
// Set the background image for *all* UINavigationBars
[[UIToolbar appearance] setBackgroundImage:gradientImage44 
                                   forBarMetrics:UIBarMetricsDefault];

更好地使用iOS 5引入的外观API.可能对您有帮助

Better to use appearance API introduced with iOS 5. May this will help you

这篇关于使用iOS5.1设置UIToolbar背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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