2012-12-05 40 views
0

我知道關於UIButtons的currentBackgroundImage屬性,但有無論如何從UIButton獲取簡單的backgroundColor?是否有可能獲得UIButton的當前背景顏色?

+0

您是否試圖從按鈕的背景顏色或背景圖像中獲取顏色? –

+0

我會建議你,不要問這個問題的答案可以用一個詞(是或否)給出。你可能會問如何獲得當前背景顏色.... :) –

+2

這個問題很容易通過查看[spec](https://developer.apple.com/library/ios/#documentation/UIKit/參考/ UIButton_Class /的UIButton/UIButton.html)。你只需要理解UIButton是UIView的子類(你可以在規範的「Inherits from」部分看到),而'backgroundColor'是UIView的屬性,而不是UIButton的屬性。 –

回答

4

如果我正確地得到您的問題,您只想獲得一個按鈕的背景顏色並存儲它?

UIColor* buttonColor = button.backgroundColor; 

backgroundColorcopy財產既具有setter和一個getter。您可以使用點符號來簡化事情。

0

根據你的問題,答案只能在YES或NO。

但我想解釋一下,是的,你可以檢索並設置你的UIButton的背景顏色。

UIButton *blueButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
//for setting 
blueButton.backgroundColor = [UIColor colorWithRed:0.0f 
              green:0.0f 
               blue:1.0 
               pha:1.0]; 
//for getting 
UIColor *myBlueButtonColor = blueButton.backgroundColor; 
相關問題