42 3. IOS SOFTWARE DEVELOPMENT TOOLS
3.2 SETTING-UP APP ENVIRONMENT
e left column in the Xcode window is called the Navigator. Here one can select or organize
different files and environment for a project.
In the Navigator Pane, the Main.Storyboard entry is seen. is is used to design the layout
of your app. Different UI elements in multiple views provided by the IDE can be used to
design the interface of an app. However, this is done programmatically here.
AppDelegate.h and AppDelegate.m are Objective-C files that can be used to handle events
such as:
app termination,
app entering background or foreground, and
app loading.
ese files are not accessed here.
e files ViewController.m and ViewController.h are used to define methods and prop-
erties specific to a particular view in the storyboard.
3.3 CREATING LAYOUT
In the file ViewController.m, the method called viewDidLoad is used to perform processes
after the view is loaded successfully. is method is used here to initialize the UI elements.
In the interface section of ViewController, add the following two properties: a label and
a button.
@interface ViewController ()
@property UILabel *label;
@property UIButton *button;
@end
Initialize the label and button and assign them to the view. is can be done by adding this code
in the method viewDidLoad :
_label = [[UILabel alloc] initWithFrame:CGRectMake (10, 15, 300, 30)];
_label.text = @"Hello World!";
[self.view, ddSubview:_label];
_button = [UIButton, buttonWithType:UIButtonTypeRoundedRect];
_button.frame = CGRectMake(10, 50, 300, 30);
[_button setTitle:@"Button" forState:UIControlStateNormal];
[self.view addSubview:_button];
3.3. CREATING LAYOUT 43
[_button addTarget:self action:@selector(buttonPress:)
forControlEvents:UIControlEventTouchUpInside];
An action is attached to the button buttonPress . is action will call a method which will be
executed when the button is pressed. As the control event is UIControlEventTouchUpInside ,
the method will be executed when the user releases the button after pressing. e method is
declared as follows:
(IBAction)buttonPress:(id)sender {
}
As of now, it is a blank method. A property will be assigned to it after specifying a C code that
is to be used to perform a signal processing function.
e app can be run by pressing the Play button on the top left of the Xcode window. An
actual target is not needed here and one may select a simulator; see Figure 3.4. For example,
iPhone 6 can be selected as the simulator.
Figure 3.4: Simulator selection.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.19.30.232