我嘗試爲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