2012-01-13 36 views
0

我試圖將圖像設置爲背景的一個UIView類型的圖像,這裏就是我如何做到這一點:背景「水印」的UIViewController中

UIImage *bgImage = [UIImage imageNamed:@"watermark.png"]; 
self.view.layer.contents = bgImage.CGImage; 
self.view.backgroundColor = [UIColor clearColor]; 

這個工程在iOS5中,但在iOS4的我得到的是黑色的背景。有任何想法嗎?

我嘗試了其他方法,如colorWithPatternImage,但沒有正確顯示圖像。

+0

這應該工作,因爲我相信,iPhone OS 2.0。確保視圖具有非零大小,並且由於其他不相關的情況,圖像不爲零。 – Costique 2012-01-13 17:26:50

回答

0

嘗試修改下聯是:

self.view.layer.contents = (id)bgImage.CGImage; 
0

你可以試試這個。

UIImageView *backgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"your_image.png"]]; 
[self.view addSubview:backgroundImage]; 
[self.view sendSubviewToBack:backgroundImage]; 
[backgroundImage release]; 

在這種情況下,您可以管理視圖層次結構,並把UIImageView當前視圖下。希望能幫助到你。

0

我覺得一切是好的,只是OK用這個你的cellForAtIndexpath

UIImage *bgImage = [UIImage imageNamed:@"watermark.png"]; 
UIImageView *imageView = [[UIImageView alloc] initWithImage:bgImage]; 
[cell.contentView addSubview: imageView]; 

我不知道是不是完美的解決方案或沒有,但我認爲它會幫助你。