图像会导致蓝色按钮

图像会导致蓝色按钮

本文介绍了在 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 图像会导致蓝色按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 08:13