2010-08-05 193 views

回答

14

您可以定義圖像按鈕按下的不同狀態。這裏有一個簡單的例子:

UIButton *submitbutton = [UIButton buttonWithType:UIButtonTypeCustom]; 
// position in the parent view and set the size of the button 
submitbutton.frame = CGRectMake(165, 20, 149, 39); 
[submitbutton setTitle:@"Submit Booking" forState:UIControlStateNormal]; 

// Add image to button for normal state 
UIImage * btnImage1 = [UIImage imageNamed:@"SubmitBooking-normal.png"]; 
[submitbutton setImage:btnImage1 forState:UIControlStateNormal]; 

// Add image to button for pressed state 
UIImage * btnImage2 = [UIImage imageNamed:@"SubmitBooking-pressed.png"]; 
[submitbutton setImage:btnImage2 forState:UIControlStateHighlighted]; 


// add targets and actions 
[submitbutton addTarget:self action:@selector(submitBookingButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; 
// add to a some parent view. 
[someview addSubview:submitbutton]; 

你可能想要自定義其他的東西。你可以閱讀更多關於這些選項here

0

另一種方式是選擇按鈕並指定你想要然後將圖像從實用工具欄來更改狀態配置,以突出顯示,然後分配上點擊圖像

看到鏈接下面的屏幕截圖

screen shot