我尝试为UIButton设置图像。但如何设置UIButton的默认图像?如何在Objective-C的Viewdidload中将默认图像设置为UIButton?
头文件中的UIButton代码如下所示。
@property (strong, nonatomic) IBOutlet UIButton *modeChangeButton;
而我尝试设置图像大小和UIButton的默认图像,但它不显示图像。代码如下所示。
- (void)viewDidLoad
{
self.modeChangeButton = [[UIButton alloc] initWithFrame:CGRectMake(200, 450, 60, 60)];
[self.modeChangeButton setBackgroundImage:[UIImage imageNamed:@"recordmode.png"] forState:UIControlStateNormal];
}
如何设置UIButton的默认图像? 在此先感谢。
当你用IBOutlet声明按钮时,它应该从storyboard或xib中加载,为什么你要创建另一个uibutton实例?如果你没有加载storyboard或xib中的按钮,为什么你不在'self.view'上添加按钮。 – KudoCC
您是否重复了自己的问题? http://stackoverflow.com/questions/23378603/why-the-sender-not-called-when-i-click-the-image-of-the-button-in-objective-c/23378773#23378773 – CrimsonChris
参见在其他问题上给出的答案! – uiroshan