开发者

Most performant way to use a background image throughout an iphone application

I have an image that I want to use as the background for every view in my application including several modal views.

Right now I'm just creating a new UIColor for each vi开发者_如何学Pythonew:

view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"metal-bg.png"]]; 

This works for the most part but with the modal views there is a brief period during the sliding animation before the background image displays when I can see through the modal view to the view below it.

Is there a better way to do this? Such as setting up some sort of global object that all the views can use?


Have you tried setting the background image in viewWillAppear:(BOOL)animated?


I was just wondering about this yesterday.

I haven't tried this, but I suspect that it may be possible to add a UIImage to the Application's delegate and then use that image in every view.

Try this:

[self.view setBackgroundColor:[[[UIApplication sharedApplication] delegate] bgImageColor]];


Perhaps you can add a subview that contains the image as the bottom view of the window object in the app delegate. Then, for any views that you add on top, you can do: self.view.backgroundColor = [UIColor clearColor] (assuming it's a UIViewController or one of its children that you're using).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜