change background image in self.view

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

  1. macrumors newbie

    Joined:
    Jul 8, 2008
    #1
    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!
     
  2. macrumors 6502a

    Joined:
    Jun 5, 2007
    #2
    is this what you need?

    Code:
    imageView.image = [UIImage imageNamed:@"picture.png"];
    
    hope it works
     
  3. macrumors 65816

    Sbrocket

    Joined:
    Jun 3, 2007
    Location:
    /dev/null
    #3
    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"];
    
     
  4. thread starter macrumors newbie

    Joined:
    Jul 8, 2008
    #4
    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!
     

Share This Page