2012-10-04 168 views
0

我試圖將圖像設置爲背景而不是顏色。這裏是我現在使用的代碼:將圖像添加到XCode項目

[testing setBackgroundColor:color]; 
[testing setFont: [UIFont fontWithName:@"Helvetica" size:33]]; 

是否有另一個[測試集]對象將背景設置爲圖像而不是顏色?我不認爲這是正確的:

[testing setImage:[UIImage imageNamed:@"test.png"] forState:UIControlStateNormal]; 

謝謝!

回答

0

嘗試

testing.backgroundColor = 
[UIColor colorWithPatternImage:[UIImage imageNamed:@"test.png"]]; 

另一種可能的解決方案會在你的筆尖/故事板在屬性檢查器中設置的圖像來製作一個UIImageView和發送的編輯器來備份>排列>發送到備份

1

您可以使用下列內容:

[testing setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"test.png"]]]; 

就個人而言,我會建議使用一個UIImageView來代替。

請注意,使用colorWithPatternImage會重複圖像以填充視圖。