本文介绍了在iOS 7中设置UIButton图像会产生蓝色按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在iOS 6 SDK上,我编写了以下代码行来显示按钮内的图像:
On iOS 6 SDK I wrote the following lines of code to display an image inside a button:
NSURL *thumbURL2 = [NSURL URLWithString:@"http://example.com/thumbs/2.jpg"];
NSData *thumbData2 = [NSData dataWithContentsOfURL:thumbURL2];
UIImage *thumb2 = [UIImage imageWithData:thumbData2];
[btn2 setImage:thumb2 forState:UIControlStateNormal];
[self.view addSubview:btn2];
但是现在使用Xcode 5和iOS 7这不起作用。该按钮不包含图像。按钮用蓝色填充。
But now with Xcode 5 and iOS 7 this doesn't work. The button doesn't contain the image. The button is filled with blue color.
推荐答案
在iOS7中有一个名为UIButtonTypeSystem的新按钮类型NS_ENUM_AVAILABLE_IOS(7_0),//标准系统按钮
In iOS7 there is new button type called UIButtonTypeSystem NS_ENUM_AVAILABLE_IOS(7_0), // standard system button
检查.xib文件并将按钮类型更改为自定义
Check your .xib file and change button type to Custom
要以编程方式执行此操作,请将此行添加到 viewDidLoad
:
To do this programmatically, add this line to the viewDidLoad
:
[UIButton buttonWithType:UIButtonTypeSystem];
这篇关于在iOS 7中设置UIButton图像会产生蓝色按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!