2014-01-12 91 views
0

使用Xcode5和storyBoard,我有幾張UIButtons及其圖片。 我需要在按下按鈕上方添加圖像,並將其刪除。 我知道如何改變它的圖像,但我需要在它上面添加圖像,保持在那裏。點擊時將圖片添加到UIButton

- (IBAction)color:(UIButton *)sender 
{ 

    if(lastButton) 
     //now remove a circle from last button 

    //add a circle to the image of the sender button 


    lastButton=sender; 
} 
+0

你可以讓這個問題更清楚一點...你想要按狀態的圖像...?當新聞稿發佈時它應該回去......?如果你需要這個,那麼你應該設置setImage的狀態... –

回答

1

您可以簡單地使用UIButton API:

if (lastButton) { 
    [lastButton setImage:imageWithoutCircle forState:UIControlStateNormal]; 
} 
[sender setImage:imageWithCircle forState:UIControlStateNormal]; 
lastButton = sender; 

或者,你可以有兩個形象的看法,一個沒有圈子,一個透明背景只包含了一圈,並在上面的透明按鈕。在你的處理器,你可以打電話

if (lastButton) { 
    circleImageViewOfLastButton.hidden = no; 
} 

你可以找出正確的圓弧觀點與tag財產,等等。但是這將是比原來的解決方案更多的代碼。

+0

正如我在問題中說的目標是在選定的按鈕上方添加一個圓圈,而不是再次創建所有的按鈕 - 用一個圓圈.. – Curnelious

+0

這是同樣的事情,只有更糟。看到我上面的編輯。 – Mundi