background image and self.view -- quick change

Discussion in 'iOS Programming' started by tawpie, Aug 2, 2008.

  1. macrumors newbie

    Jul 8, 2008
    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.

    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.

    Suggestions are highly appreciated!
  2. Moderator emeritus


    Jun 15, 2000
    How are you doing it without subviews? You can assign self.view to an image view - it doesn't have to be a normal view.
  3. thread starter macrumors newbie

    Jul 8, 2008
    yep, I haven't gotten subviews "down" yet... soon though. Turns out you can do what I wanted. The solution is that self.view can be a UIImageView, but the compiler doesn't quite know about it so the .image property doesn't function UNLESS you tell the compiler it's dealing with a UIImageView. I had figured if you can assign a UIImageView to self.view you should be able to modify the .image property, thanks to Sbrocket for this solution, which tells the compiler that self.view has a .image property:

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

Share This Page