Setting Up 2 Images

Discussion in 'iOS Development' started by ZunePod, Jun 15, 2009.

  1. ZunePod

    ZunePod Banned

    Joined:
    Aug 28, 2008
    Messages:
    1,340
    Likes Received:
    0
    Device:
    iPhone 3G (Black)
    I've studied some source code, and tryed to do the same thing as in the source code, but with 2 images instead of one.

    I can't show 2 images on the screen, no matter what I do.

    Halp?
  2. spoonforknife

    spoonforknife Retired Moderator

    Joined:
    Nov 15, 2007
    Messages:
    6,896
    Likes Received:
    317
    Code:
    imageOne = [[UIImageView alloc] initWithFrame: CGRect(point.x, point.y, 40, 40)];
    [imageOne setImage: [UIImage imageNamed:@"yourImage.png"]];
    
    imageTwo = [[UIImageView alloc] initWithFrame: CGRect(point.x, point.y, 40, 40)];
    [imageTwo setImage: [UIImage imageNamed:@"yourImageTwo.png"]];
    
    [window addSubview: imageOne];
    [window addSubview: imageTwo];
    Make sure you're adding the ImageViews as subviews. Also make sure you're synthesizing imageTwo and that imageOne and imageTwo have different frames.
  3. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    and remember to release them

    Please Register or Log in to view images

  4. ZunePod

    ZunePod Banned

    Joined:
    Aug 28, 2008
    Messages:
    1,340
    Likes Received:
    0
    Device:
    iPhone 3G (Black)
    Thanks, but I have 2 errors

    Code:
    - (void)loadView
    {
    	imageOne = [[UIImageView alloc] initWithFrame: CGRect(0, 20, imageOne.size.width, imageOne.size.height];
    	[imageOne setImage: [UIImage imageNamed:@"Up.png"]];
    	
    	imageTwo = [[UIImageView alloc] initWithFrame: CGRect(0, 250, imageTwo.size.width, imageTwo.size.height)];
    	[imageTwo setImage: [UIImage imageNamed:@"Down.png"]];
    	
    	[window addSubview: imageOne];
    	[window addSubview: imageTwo];
    	
    }
    
    The first one says:

    Expected expression before CGRect. But it only occurs on the imageOne.

    The second:

    Expected ';' before '}'. Now I checked all of my end of lines, and they all had the ; at the end.

    Any ideas?
  5. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    Fixed the code, he was missing a ')'.
  6. spoonforknife

    spoonforknife Retired Moderator

    Joined:
    Nov 15, 2007
    Messages:
    6,896
    Likes Received:
    317
    Thanks homeskillet.
  7. ZunePod

    ZunePod Banned

    Joined:
    Aug 28, 2008
    Messages:
    1,340
    Likes Received:
    0
    Device:
    iPhone 3G (Black)
    Still get the first error
  8. Cyanidepoison

    Cyanidepoison Active Member

    Joined:
    Jan 18, 2008
    Messages:
    1,076
    Likes Received:
    2
    You're doing it wrong. There aren't any errors in the code as long as you have defined all your variables.
  9. spoonforknife

    spoonforknife Retired Moderator

    Joined:
    Nov 15, 2007
    Messages:
    6,896
    Likes Received:
    317
    Post your full code, you're doing something wrong.

    Did you define imageOne.size.width, etc?

Share This Page