window setBackgroundColor to window setBackgroundImage???

Discussion in 'iOS Development' started by Rockstarou812, Feb 15, 2009.

  1. Rockstarou812

    Rockstarou812 New Member

    Joined:
    Jan 17, 2009
    Messages:
    43
    Likes Received:
    0
    Well I am new at making iPhone apps, but I am familiar with Xcode.

    I need a n00b explanation on how to do the following, and why what I am doing won't work

    Please Register or Log in to view images




    First I had this code which allowed me to draw on the UIWindow

    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [window setBackgroundColor:[UIColor blackColor]];


    I want to change the background to an image, not the plain black. SO I changed that to this:


    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [window setBackgroundImage:[UIImage imageNamed

    Please Register or Log in to view images

    "Default.png"]];


    That didn't work, it compiled, but then closed.



    I played around with the code and changed it to green to see if I noticed anything:



    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [window setBackgroundColor:[UIColor greenColor]];




    the screen was plain black, BUT when I click the home button the screen turns green for a split second as it closes.


    this is a basic draw/painter app, does anyone know where and what I need to change to get an image in the background so I can color on it? Thanks.


    Sorry if I wrote this extremely confusing

    Please Register or Log in to view images

  2. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    you dont set a background colour for a window it for a view and an alternative could just be using a UIImageView ontop of the view but i dont recommend that
  3. Spreche

    Spreche Member

    Joined:
    Dec 27, 2007
    Messages:
    164
    Likes Received:
    0
    Device:
    iPhone
    Well UIWindow doesn't have the method 'setBackgroundColor:' but UIView does. So what you have to do is create a UIView object then place the view inside the window. Then you set the color or image.

    Code:
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    view = [[UIView alloc] init];
    [window makeKeyAndVisible];
    [window addSubview:view];
    
    image = [[UIImageView alloc] initWithImage:@"Default.png"];
    //[view setBackgroundColor:[UIColor blackColor]];
    [view addSubview:image];
    
    
    
  4. Rockstarou812

    Rockstarou812 New Member

    Joined:
    Jan 17, 2009
    Messages:
    43
    Likes Received:
    0
    Okay what I want is to be able to draw OVER the background image. I am using a little Open GL to draw... so I think this is the code I should be editing in AppController.m




    Code:
    @implementation AppController
    
    - (void) applicationDidFinishLaunching:(UIApplication*)application
    {
    	CGRect					rect = [[UIScreen mainScreen] applicationFrame];
    	CGFloat					components[3];
    	
    	//Create a full-screen window
    	window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    	[window setBackgroundColor:[UIColor blackColor]];
    So how should I incorporate what you guys are talking about directly into there? I want to get an image, lets just say Default.png


    Thanks for the quick responses, hopefully I will get some more

    Please Register or Log in to view images

  5. spoonforknife

    spoonforknife Retired Moderator

    Joined:
    Nov 15, 2007
    Messages:
    6,896
    Likes Received:
    317
    Code:
    window.backgroundColor = [UIColor greenColor];
    Try that.
  6. Rockstarou812

    Rockstarou812 New Member

    Joined:
    Jan 17, 2009
    Messages:
    43
    Likes Received:
    0
    spoon, do you have an msn? It would be great if I could easily message you.

    I used that code and it was black normally, but when I clicked the home button to close it it showed the green screen as it shrinked away. My guess is that the green is being blocked by a black color layer somehow.

    suggestions?
  7. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    exactly what I said but in more detail
  8. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    A UIWindow is a subclass of UIView. You can use any UIView method or property with a UIWindow. That is, window.backgroundColor = [UIColor magentaColor] will work just fine. There is no setBackgroundImage property for UIViews or even UIImageViews**. I'm not sure where you picked that up at all.

    I would recommend looking at the sample Open GLES project Xcode has if you want to see how to properly construct your view hierarchy.





    **Exceptions: UIViews/UIImageViews that have been subclassed.
  9. Rockstarou812

    Rockstarou812 New Member

    Joined:
    Jan 17, 2009
    Messages:
    43
    Likes Received:
    0
    Thanks Skylar and everyone who helped me out, I think I made up that setbackgroundImage, because I don't know where I go t that either...
  10. kashif_pucitian

    kashif_pucitian New Member

    Joined:
    Aug 11, 2011
    Messages:
    3
    Likes Received:
    0
    Make size of UIWindow to 320,50

    If UIWindow is SubClass of UIView than why UIWindow donot allow me to customize it's width and height.

    I want my Main window to be of size (0,250,320,50) .
    My concept is to make "news Ticker" and thats why my application window should of small size so user will at a time see news ticking as well as user will interact with iPhone built-in applications like SMS , Safari etc.
    Like when i double click on iphone "task manager" has been pop-up and user at a time interact either with "task manager" or with other installed applications.

    Kindly help me out.
    Kashif
    kashif.pucitian@gmail.com

Share This Page