Top of the page
Close

This is a red error

This is a red error

This is a red error

Hello World iPhone Tutorial

Ondrej Rafaj on 2009.07.01 09:16:07

A screencast tutorial to help beginner iPhone programmers get started. This tutorial shows how to draw "Hello World!" text on the screen.

 

 

Source code:

import "MyView.h"

#define TEXT_LABEL_FONT_SIZE 30.0
#define TEXT_FIELD_HEIGHT_MULTIPLIER 2.0

@implementation MyView

- (id)initWithFrame:(CGRect)aRect
{
[super initWithFrame:aRect];
self.backgroundColor = [UIColor whiteColor];

CGRect contentFrame = self.frame;
CGFloat leftMargin = 90.0;
CGFloat textFieldWidth = contentFrame.size.width * 0.72;
CGFloat textFieldOriginX = (contentFrame.size.width - textFieldWidth) / 2.0;

CGRect labelFrame = CGRectMake(textFieldOriginX, leftMargin, textFieldWidth, TEXT_LABEL_FONT_SIZE * TEXT_FIELD_HEIGHT_MULTIPLIER);
UILabel *someText = [[UILabel alloc] initWithFrame:labelFrame];
someText.text = @"Hello World!";
someText.font = [UIFont systemFontOfSize:TEXT_LABEL_FONT_SIZE];
someText.textColor = [UIColor redColor];
someText.textAlignment = UITextAlignmentCenter;

[self addSubview:someText];
[someText release];

return self;
} 

Ondrej Rafaj

Ondrej Rafaj

Technical director @ Fuerte International

Back to top Comment

Comments ... Why not to get involved!
HTML Comment Box is loading comments...

Old comments:

Back to top

IE SUCKS, DON'T USE IT :) Digg this page