Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.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 按下按钮时,按钮会褪色_Ios_Objective C_Xcode_Uibutton - Fatal编程技术网

Ios 按下按钮时,按钮会褪色

Ios 按下按钮时,按钮会褪色,ios,objective-c,xcode,uibutton,Ios,Objective C,Xcode,Uibutton,我已将UIButton的正常状态设置为一个图像,并将其高亮显示状态设置为另一个图像。按钮正常是好的,但当我按下按钮时,它将设置为图像的灰色褪色版本。在下图中,按下顶部的灰色按钮,其他按钮处于正常状态。这些按钮是通过编程制作的 UIButton *button; UIImage *bluenormalImage = [UIImage imageNamed:@"bluebuttonnormal.png"]; UIImage *bluepressedImage = [UIImage imageNam

我已将UIButton的正常状态设置为一个图像,并将其高亮显示状态设置为另一个图像。按钮正常是好的,但当我按下按钮时,它将设置为图像的灰色褪色版本。在下图中,按下顶部的灰色按钮,其他按钮处于正常状态。这些按钮是通过编程制作的

UIButton *button;

UIImage *bluenormalImage = [UIImage imageNamed:@"bluebuttonnormal.png"];
UIImage *bluepressedImage = [UIImage imageNamed:@"bluebuttonpushed.png"];

[button setBackgroundImage:bluenormalImage forState:UIControlStateNormal];
[button setBackgroundImage:bluepressedImage forState:UIControlStateHighlighted];

好的,我没有意识到文字不是图像的一部分。改为这样做:

据我所见,您需要将按钮正确初始化为自定义类型。当按钮类型为system(系统)时,会出现突出显示问题

将按钮变量行更改为以下内容:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
如果稍后对其进行初始化,则可以在设置背景图像之前执行以下操作

UIButton *button 
button = [UIButton buttonWithType:UIButtonTypeCustom];

这不会挡住文字吗?好的,我已经更新了我的帖子,因为我没有意识到文字不是图片的一部分。按钮只需要初始化为自定义类型。按钮不是空指针吗?