Results 1 to 4 of 4

Your favorite Apple, iPhone, iPad, iOS, Jailbreak, and Cydia site.

Thread: Simple app to display an image

  1. #1
    Default Simple app to display an image
    I just want to make a simple app to display my college schedule contained in a PNG when I tap the icon. The file is in the folder and called "s.png". My code does not display the image; the program compiles but does notihng when launched, it just sits there at a black screen until i hit the home button. Can anyone tell me what I'm doing wrong? My experiencw with ObjC is limited and thus, I'm using an existing HelloWorld app as a template to accomplish my goal. (I do not intend to publicly release the program in the interest of code originality.)

    #import "HelloWorldApp.h"

    @implementation HelloWorldApp
    - (void) applicationDidFinishLaunching: (id) unused
    UIWindow *window;

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

    myImage = [UIImageView alloc];
    initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
    [myImage setImage:[UIImage imageNamed:@"s.png"]];

    mainView = [[UIView alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
    [mainView addSubview:myImage];

    [window makeKeyAndVisible];
    [window addSubview: mainView];


  2. #2

  3. #3
    CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0f, 109.0f);
    UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];
    [myImage setImage:[UIImage imageNamed:@"s.png"]];
    myImage.opaque = YES; // explicitly opaque for performance
    [self.view addSubview:myImage];
    [myImage release];

  4. #4
    Join Date
    Jun 2009
    Thanked 5 Times in 5 Posts

    It can be done without any coding and I think that should be better than anything.Drag an image from the finder to the resources section of the project outline. Xcode infers the action from the file type, and images will be copied to the Resources folder.
    Once the image is added to your project, the UIImageView inspector image name will autocomplete your image name, and all should work.
    mod/edit links removed

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts