设置 UIButton 图像会导致 iOS 7 中的蓝色按钮 [英] Setting UIButton image results in blue button in iOS 7

查看:14
本文介绍了设置 UIButton 图像会导致 iOS 7 中的蓝色按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 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]; 

这篇关于设置 UIButton 图像会导致 iOS 7 中的蓝色按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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