Hello World Tutorial
From GameOver
Contents |
Introduction
The infamous Hello World program. A simple window that displays the white text Hello World with a blue background.
Screenshots
Requirements
This program requires the iPhone Toolchain to compile. You can view how to obtain and install it here.
Packaged Files
For your convenience this projects source code and compiled code is avaiable for download in the following formats: tar.bz2, zip
Source Code
README
All files contained herein are under the copyright notice and license contained below. It is omitted from each individually displayed file for redundancy purposes only.
helloWorld - iPhone basic "hello world" application. Copyright (C) 2007 David Supuran <http://www.iphonegameover.com> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
helloWorld.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <UIKit/UIApplication.h>
@interface helloWorld : UIApplication {
}
- (void) applicationDidFinishLaunching: (id) unused;
@end
helloWorld.m
#import <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>
#import <UIKit/UIWindow.h>
#import <UIKit/UIView-Hierarchy.h>
#import <UIKit/UIHardware.h>
#import <CoreGraphics/CGColor.h>
#import "helloWorld.h"
@implementation helloWorld
- (void) applicationDidFinishLaunching: (id) unused
{
/* RGBA - Red Blue Green Alpha color defintions */
float blue[4] = { 0.0f, 0.0f, 1.0f, 1.0f };
float white[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
struct CGRect rect = [UIHardware fullScreenApplicationContentRect];
rect.origin.x = rect.origin.y = 0;
/* Initialize the main window */
UIWindow* window = [[UIWindow alloc] initWithContentRect: rect];
[window orderFront: self];
[window makeKey: self];
[window _setHidden: false];
/* Initialize the main view */
UIView* mainView = [[[UIView alloc] initWithFrame: rect] autorelease];
[window setContentView: mainView];
/* Initialize a text label with static, uneditable text */
UITextLabel *_title = [[UITextLabel alloc] initWithFrame: rect];
[_title setText: @"Hello World!"];
[_title setBackgroundColor: CGColorCreate(CGColorSpaceCreateDeviceRGB(), blue)];
[_title setColor: CGColorCreate(CGColorSpaceCreateDeviceRGB(), white)];
[_title setCentersHorizontally: true];
[mainView addSubview: _title];
}
@end
main.m
#import <UIKit/UIKit.h>
#import "helloWorld.h"
int main(int argc, char **argv)
{
int ret;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
ret = UIApplicationMain(argc, argv, [helloWorld class]);
[pool release];
return ret;
}
Makefile
NAME := helloWorld
VERSION := 0.1
CC := arm-apple-darwin-gcc
CFLAGS := -Wall -pipe -ansi -O3
LD := ${CC}
LDFLAGS := -lobjc -framework CoreFoundation -framework Foundation -framework UIKit -framework LayerKit -framework CoreGraphics
all: ${NAME}
helloWorld: main.o ${NAME}.o
$(LD) $(LDFLAGS) -o $@ $^
%.o: %.m
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
clean:
rm -f *.o ${NAME}

