Monday, September 17, 2012

your first "HELLO WORLD" app in your iphone (up to 4.2 iOS)


Writing and Compiling Your Program


 The window you are seeing now is the main IDE program. It has the editor and controls for the compiler built into it. We will now add the code to create a button and a button action.

1. Expand the “Classes” group on the left side by clicking on the small triangle next to it.

2. Click on “HelloWorldViewController.m”.

3. Scroll down to the second green code region. This is a code comment showing where to put your code if you are creating your user interface using code.

4. Highlight the whole comment from the “/*” line to the “*/” line and paste or type the following code in it's place:- (void)viewDidLoad { [super viewDidLoad]; UIButton* helloButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; helloButton.bounds = CGRectMake(0.0f, 0.0f, 200.0f, 50.0f); helloButton.center = self.view.center; helloButton.font = [UIFont boldSystemFontOfSize:30.0f]; [helloButton setTitle:@"Hello" forState:UIControlStateNormal]; [helloButton addTarget:self action:@selector(helloButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:helloButton]; } - (void) helloButtonPressed:(id)sender { [(UIButton*)sender setTitle:@"Hello World!" forState:UIControlStateNormal]; }

MORE SOURCES OF HOW TO DO IT HERE (PDF DOWNLOADABLE)


No comments:

Post a Comment