将背景图像添加到UIView的正确方法是什么?

时间:2011-05-27 09:49:44

标签: iphone objective-c cocoa-touch uiview

在几个论坛上读到添加带有“colorWithPatternImage”的背景图像会比平常消耗更多的内存。

糟糕的方式:

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]]; 

更好的解决方案:

UIImageView* iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]]; iv.userInteractionEnabled = YES; 
self.view = iv; 
[iv release];

我有两个问题!哪种解决方案更好?为什么? 我也想弄清楚如何将标签放在imageView的顶部。

1 个答案:

答案 0 :(得分:2)

UIColor* tmpColor=[[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"background.png"]];  
self.view.backgroundColor=tmpColor;  
[tmpColor release];