目前我正在iPhone應用程序中創建兩個按鈕併爲兩個按鈕設置圖像,當用戶觸摸button2然後在button2內顯示button1圖像時,我最好地嘗試了我的級別,但我無法修復此問題,請任何一個幫我如何在iPhone中獲取按鈕背景圖片?
由於提前
我嘗試這樣做:
btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
[btn1 setImage:[UIImage imageNamed:@"4.png"] forState:UIControlStateNormal];
btn1.frame=CGRectMake(61, 60, 50, 50);
[btn1 addTarget:self action:@selector(Button1Method) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn1];
btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
[btn2 setImage:[UIImage imageNamed:@"8.png"] forState:UIControlStateNormal];
btn2.frame=CGRectMake(112, 60, 50, 50);
[btn2 addTarget:self action:@selector(Button2Method) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn2];
-(void)Button2Method
{
[btn2 setImage:[UIImage imageNamed:btn1.currentBackgroundImage] forState:UIControlStateNormal];
}