I’m using a header file to set the background for my application. I have something like:
#define backgroundImage [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.jpeg"]]
but I want use UIImageView instead of UIColor. I know I can do:
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)
[imageView setImage:[UIImage imageNamed:@"background.png"]];
self.tableView.backgroundView = imageView;
but how do I use it with #define?
#define is a preprocessor directive. What this is going to do is anywhere you use
backgroundImageyou will get[UIColor colorWithPatternImage:[UIImage imageNamed:@"background.jpeg"]]The best way to handle this is use the #define to specify the image name:
And then use that in your code:
If you want to however, you can do:
And:
// Use the table view bounds so the background view is the size of the table view
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.tableView.bounds;
If you choose to make the whole code block a preprocessor define, you can use
\to make new lines.