Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

tawpie

macrumors newbie
Original poster
Jul 8, 2008
18
0
ok... I put a background image on my app, sort of like wallpaper. It's pretty easy to do, I start with a UIImageView, set the background image, add some labels and buttons, then copy it to self.view. My view is created programmatically... IB wouldn't do what I wanted so the view creation activity occurs in the loadView method in my mainViewController.

Now, I want to change the background image only, not the labels, not the buttons BUT since self.view is evidently not a UIImageView, one cannot set the background image.

I tried a mutable copy of self.view to a "new" UIImageView, that blows up at the mutable copy.

I can do it via subviews but that seems like a longer way around since I get to create my buttons and labels for each different wallpaper.

I haven't been able to locate much on "self.view" in the documentation, it started showing up in examples and obviously belongs to the view controller but what is it and where did it inherit from?

Suggestions are highly appreciated!
 

macfanboy

macrumors 6502a
Jun 5, 2007
916
163
is this what you need?

Code:
imageView.image = [UIImage imageNamed:@"picture.png"];

hope it works
 

Sbrocket

macrumors 65816
Jun 3, 2007
1,250
0
/dev/null
As long as you actually did what you described and set self.view to the UIImageView you created, then it is an instance of UIImageView. The problem you're probably running into is the the view property of a UIViewController is defined more generally as a UIView, so you need to make sure the compiler knows that it is a UIImageView and doesn't complain with an error.

Code:
((UIImageView*)self.view).image = [UIImage imageNamed:@"myNewImage.png"];
 

tawpie

macrumors newbie
Original poster
Jul 8, 2008
18
0
wow -- that was exactly the solution. Thank you Sbrocket.

The compiler certainly behaved as if the image property wasn't "there", which led me to wonder what it actually thought the view property was... but I had no idea you could "tell" the compiler that self.view is really a UIImageView.

Again thanks!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.