UIImageView

Discussion in 'iOS Development' started by Chicken, Oct 31, 2008.

  1. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    When i try to use UIImage View it compiles correctly yet never shows up in my application can anyone show me a snippet of working UIImageView code thanks!
  2. bddckr

    bddckr Active Member

    Joined:
    Dec 2, 2007
    Messages:
    1,434
    Likes Received:
    18
    Device:
    iPhone 4 (Black)
    Code:
    UIImageView *myView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myImage.png"]];
    [window addSubview:myView];
    
  3. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    right thanks I will try it now
    ------------------double post merged------------------
    right thanks so much it works but it is small how can I get it the size of the screen (I also have a nav bar) also it is in the top right coner how can I move it thanks for your help
  4. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Code:
    UIImageView *theImageView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    theImageView.image = [UIImage imageNamed:@"theNameOfYourImage.png"];
    
    //Assuming this is within a standard view controller, use the next line.
    [self.view addSubview:theImageView];
    //else:
    //[anotherView addSubview:theImageView];
    
    [theImageView release];
  5. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    will try as soon as I have finished installing a service pack for my computer
    ------------------double post merged------------------
    I get an error UIScreen undeclared I didn't think I had to declare it how do I declare UIScreen in my header file by the way I'm using the cydia toolchain
    ------------------double post merged------------------
    right I've fixed everything got the navBar and the image showing now i need the co-ordinates for the image all I have is a nav bar what are the co-ordinates to make the image fill the rest of the screen thanks
  6. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    In whichever object you are working with, add this before the interface
    @class UIScreen;

    On 2.x, Apple strongly recommends apps that adhere strictly to the MVC design pattern for your apps. What you should be doing is creating a navigation controller and pushing to your view controller. That way, you won't need to worry about adjusting the view for the navigation bar. If you don't want to follow MVC and set up a navigation controller, then change your init line for your image view to:
    Code:
    UIImageView *theImageView = [[UIImageView alloc] initWithFrame:CGRectMake([[UIScreen mainscreen] bounds].origin.x, [[UIScreen mainscreen] bounds].origin.y +48, [[UIScreen mainscreen] bounds].size.width, [[UIScreen mainscreen] bounds].height - 48)];

Share This Page