Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为什么带有UIButton的UICollectionViewCell具有单色/着色图像?_Ios_Objective C_Uibutton_Uiimage_Ios7 - Fatal编程技术网

Ios 为什么带有UIButton的UICollectionViewCell具有单色/着色图像?

Ios 为什么带有UIButton的UICollectionViewCell具有单色/着色图像?,ios,objective-c,uibutton,uiimage,ios7,Ios,Objective C,Uibutton,Uiimage,Ios7,我创建了一个UICollectionView并添加了一个单元格,其中唯一的子视图是UIButton。该按钮具有其标题和图像集。我已经在调试器中验证了图像数据是否正确 当按钮被画在屏幕上时,我看到了文本和图像,但是图像看起来好像是用色调填充的,模糊了除形状以外的所有图像 我在这里遗漏了什么,让它显示为一个正常的按钮 更新 事实证明,这并非特定于UICollectionView,而是iOS7中的所有UIButton iOS 7使按钮中的所有图像都像模板图像一样,使用图像的alpha通道和色调颜色生成

我创建了一个UICollectionView并添加了一个单元格,其中唯一的子视图是UIButton。该按钮具有其标题和图像集。我已经在调试器中验证了图像数据是否正确

当按钮被画在屏幕上时,我看到了文本和图像,但是图像看起来好像是用色调填充的,模糊了除形状以外的所有图像

我在这里遗漏了什么,让它显示为一个正常的按钮

更新 事实证明,这并非特定于UICollectionView,而是iOS7中的所有UIButton

iOS 7使按钮中的所有图像都像模板图像一样,使用图像的alpha通道和色调颜色生成图像(非常类似于选项卡栏中的图像)。UIImage上有一个新的renderingMode属性,默认为“自动”,由上下文决定(这是按钮的模板样式)

使用UIImage上的新:方法可以避免此问题:

UIImage* myImage = [UIImage imageNamed:@"Foo.png"];
myImage = [myImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[button setImage:myImage forState:UIControlStateNormal];

避免这种情况的最简单方法是使用不同的
UIButtonType
。IOS 7上的
UIButtonTypeSystem
具有此行为,因此您可以使用自定义按钮:

UIButton *button = [UIButton buttonWithType: UIButtonTypeCustom];
[button setImage:myImage forState:UIControlStateNormal];
当UIButton的背景色以这种方式显示文本时,它不会关闭按钮图像

UIButton.backgroundColor = UIColor.lightText