March 12, 2008
4
iPhone Hello World Using UILabel
By Levi Senft in iPhone
In this version of my iPhone Hello World app I’m using a UILabel widget to display the text instead of a UITextView. I’m also centering the label.
helloworldAppDelegate.h:
1 2 3 4 5 6 7
8 #import <UIKit/UIKit.h>
9
10 @class MyView;
11
12 @interface helloworldAppDelegate : NSObject {
13 UIWindow *window;
14 MyView *contentView;
15 16 UILabel *label;
17 }
18
19 @property (nonatomic, retain) UIWindow *window;
20 @property (nonatomic, retain) MyView *contentView;
21 22 @property (nonatomic, retain) UILabel *label;
23
24 @end
25
helloworldAppDelegate.m
1 2 3 4 5 6 7 8
9 #import "helloworldAppDelegate.h"
10 #import "MyView.h"
11
12 @implementation helloworldAppDelegate
13
14 @synthesize window;
15 @synthesize contentView;
16 17 @synthesize label;
18
19 - (void)applicationDidFinishLaunching:(UIApplication *)application {
20 21 self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
22
23 24 self.contentView = [[[MyView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
25 [window addSubview:contentView];
26
27 28 29 CGFloat x = 320/2 - 120/2;
30 31 CGFloat y = 480/2 - 45/2;
32 CGRect rect = CGRectMake(x , y, 120.0f, 45.0f);
33
34
35
36
37
38 39 self.label = [[[UILabel alloc] initWithFrame:rect] autorelease];
40 41 [label setText:@"Hello World!"];
42 43 [label setTextAlignment:UITextAlignmentCenter];
44
45 46 [contentView addSubview:label];
47
48 49 [window makeKeyAndVisible];
50 }
51
52 - (void)dealloc {
53 54 [label release];
55 [contentView release];
56 [window release];
57 [super dealloc];
58 }
59
60 @end
61
Tags: iPhone
Nice Site!
http://google.com
Thank you,
Your tutorial helped me, to write a simple application.
i want a bigger text to display on iphone screen. Means number of words are more. when i write a label like that it is not showing full sentence.
Can you tell me how i will get it done.
gtà(oiiu-èipçiop__oàit(‘u-(ç _utit (_ ç-è_eè(àçi(‘à’à)(àç oitujjuo_iopùkuujjjjjjjjjjyiiiiiiiiiiiiiiiiioujuyoiùopujuopi^àupuko^p _uoèiuoppyiujyioyuoiroioàtotpotototooyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyihlkimoioooooooo ppp$=^^^^^^^^^^^^^^^^^^^^^^^^^^^plopo^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
the content what we are added is not stand still in the screen. It appears & disappears when we press the down button. What we have to do inorder to make the text to stand still in the screen?