2011-03-20 56 views
0

在代碼中,我設置了以下內容: btnLogo.SetImage(UIImage.FromBundle(「images/Zouak_logo_button.png」),UIControlState.Normal); btnLogo.SetImage(UIImage.FromBundle(「images/Zouak_logo_button_pushed.png」),UIControlState.Selected);自定義按鈕不會顯示我的圖片爲推送狀態

我無法找到一個UIControlState.Pressed或Pushed或任何沿着這些線。當按下按鈕時,它不會顯示我想要的圖像版本。我是否需要手動在Click事件中執行此操作?

回答

1

我覺得你的語法是有點奇怪,但我猜你想做的事:

UIButton *btn = [[UIButton alloc] init]; 
[btn setImage:uiimg forState:UIControlStateHighlighted]; 
+0

其中uiimg = UIImage.FromBundle(「圖像/Zouak_logo_button_pushed.png「)。 – uvesten 2011-03-20 15:24:27

+0

我看到我的錯誤,這是我認爲它是選定狀態,而不是突出顯示。謝謝。 – 2011-03-20 17:27:19

1

這樣做對所有國家:

UIImage *newNormalImage = [UIImage imageNamed:@"images/Zouak_logo_button.png"]; 
[btnLogo setBackgroundImage:newNormalImage forState:UIControlStateNormal]; 
// Image for highlighted state 
UIImage *newHighlightedImage = [UIImage imageNamed:@"mages/Zouak_logo_button_pushed.png"]; 
[btnLogo setBackgroundImage:newHighlightedImage forState:UIControlStateHighlighted]; 
// Image for selected state 
UIImage *newSelectedImage = [UIImage imageNamed:@"mages/Zouak_logo_button_pushed.png"]; 
[btnLogo setBackgroundImage:newSelectedImage forState:UIControlStateSelected]; 
相關問題