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
Objective c 我能';t以编程方式显示图像_Objective C_Uibutton_Uiimage - Fatal编程技术网

Objective c 我能';t以编程方式显示图像

Objective c 我能';t以编程方式显示图像,objective-c,uibutton,uiimage,Objective C,Uibutton,Uiimage,我正试图在我正在使用的IOS(iPad)应用程序上从我的桌面加载并显示png。我需要以编程的方式来做,而不是用故事板。这是我的密码 UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom]; [myButton addTarget:self action:@selector(myCustomFunction:) forControlEvents:UIControlEventTouchUpInside]; [myBu

我正试图在我正在使用的IOS(iPad)应用程序上从我的桌面加载并显示png。我需要以编程的方式来做,而不是用故事板。这是我的密码

    UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
[myButton addTarget:self action:@selector(myCustomFunction:) forControlEvents:UIControlEventTouchUpInside];
[myButton setBackgroundImage:[UIImage imageNamed:@"annie.png"] forState:UIControlStateNormal];
myButton.frame = CGRectMake(14.0, 10.0, 74.0, 46.0);
myButton.frame = CGRectMake(4000, 4000, 4000, 4000);
[self.view addSubview:myButton];
当我运行应用程序时,(使用IOS模拟器),它只会给我一个空白的白色屏幕。我是编程新手,我确信我遗漏了一些非常明显的东西。但我不知道是什么…我没有得到任何错误,但它只是不显示照片。我需要照片以UIbutton的形式,因为它可能需要有触摸选项。
谢谢

这条线路几乎肯定会引起问题。摆脱它

myButton.frame = CGRectMake(4000, 4000, 4000, 4000);
不要立即设置图像,而是尝试设置一些文本以确保按钮出现

[myButton setTitle:@"I am a button" forState:UIControlStateNormal];
最后,尝试设置图像(而不是背景图像)


这个答案是正确的。主要是
setImage:
setBackgroundImage:
之间的区别。哇!谢谢你,能够做到这一点是我计划的50%。我终于可以前进了。谢谢
[myButton setImage:[UIImage imageNamed:@"annie.png"] forState:UIControlStateNormal];