Thread: Simple app to display an image
-
09-05-2009, 05:18 PM #1
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];
}
@end
-
09-06-2009, 08:18 AM #2
I think a better solution would be to display what you need in a UITableView.
iPhone Developer
Twitter: @Gojohnnyboi
Email: [email protected]
Anthrax ram disk kit developer, hacker.
-
10-24-2009, 11:01 PM #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];
-
10-25-2009, 03:59 AM #4
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



LinkBack URL
About LinkBacks
Reply With Quote
