2012-01-05 40 views
0

對於UIButton在視圖之一,我創建了一個圖像用於正常狀態,但我想繼續使用默認的藍色/圖像的突出顯示/選擇狀態, 有沒有辦法做到這一點?或者我是否真的必須爲突出顯示/選擇準備定製圖像?UIButton定製使用標準的圖像/顏色爲突出顯示的狀態

下面是我每@mashios要求和意見有如下的代碼 -

UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
[shareButton setFrame:CGRectMake(1.0, 0.0, 99.0, 43.0)]; 
[shareButton setBackgroundImage:[[UIImage imageNamed:@"share_normal"] 
           stretchableImageWithLeftCapWidth:0.0 
           topCapHeight:0.0] forState:UIControlStateNormal]; 
[shareButton setBackgroundImage:[[UIImage imageNamed:@"share_normal"] // bottom_up_left_3_selected 
           stretchableImageWithLeftCapWidth:0.0 
           topCapHeight:0.0] forState:UIControlStateHighlighted]; 
[shareButton addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside]; 

回答

-1

可以相同的圖像設置爲兩種狀態。

+0

我剛剛試驗過,通過將相同的圖像(用於正常狀態)設置爲突出顯示的狀態。結果不是我想要的,而是點擊按鈕時根本沒有顏色變化。 – tom 2012-01-09 18:24:49

+0

你可以只提供一些代碼。 – mashios 2012-01-10 04:48:16

+0

請查看我的帖子,上面有我使用的代碼 – tom 2012-01-10 09:29:06

-1

首先,你需要相同的圖像爲正常,突出顯示和選擇狀態。在另一個評論中,你想改變按鈕的顏色。雖然我想建議你幾件事。 1.將圖像設置爲按鈕pls時。傳遞完整的字符串像(something.jpg)。 2.僅在需要時才使用stretchableImageWithLeftCapWidth & topCapHeight。 3.設置圖像像這樣[[shareButton setBackgroundImage:[[UIImage imageNamed:@「share_normal.jpg/png」] forcontrolstate:UIControlStateNormal]; 4.我只是改變這些東西,它爲我工作。

相關問題