Custom background image set up in main.m that is used in the whole app?
How can I add a custom image (or hex color) to main.m that will be used in the whole application and all it's views开发者_StackOverflow?
Don't set it up in the main.m. Use your AppDelegate for that. A solution could look like this:
YourAppDelegate.h
YourAppDelegate : UIApplication <UIResponder> {
UIImageView *myGlobalBackgroundImage;
}
@property (nonatomic, retain) UIImageView *myGlobalBackgroundImage;
YourAppDelegate.m
@implementation YourAppDelegate
@synthesize myGlobalBackgroundImage;
-.....applicationDidFinishLaunching....{
myGlobalBackgroundImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"imagefilename.ext"]];
}
Then grab that ivar from within your UIViewController and add it as a subview in the viewDidLoad method.
精彩评论