44 2. SOFTWARE DEVELOPMENT TOOLS
2.2.3 CREATING LAYOUT
In the file ViewController.m, the method called viewDidLoad is used to perform processes
after the view has 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. en, 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 addSubview:_label];
_button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
_button.frame = CGRectMake(10, 50, 300, 30);
[self.view addSubView:_button];
[_button addTarget:self action:@selector(buttonPress:)
forControlEvents:UIControlEventTouchUpInside];
An action is attached to the button buttonPress . is action will call the method which
gets executed when the button is pressed. As the control event is UIControlEventTouchUpIn-
side, the method gets executed when the user releases the button after pressing. is method is
declared as follows:
(IBAction)buttonPress:(id)sender {
}
As of now, it is a blank method. A property is assigned to it after specifying the 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 my select the simulator; see Figure 2.30. For example,
iPhone 6 can be selected as the simulator.
When the app is run, the label “Hello World!” can be seen and the button gets created.
On clicking the button, nothing happens. is is because the method to handle the button press
is empty.
It is not required to know the Objective-C syntax. Note that one can call a C function in
Objective-C just by including a header. Objective-C is useful for handling iOS APIs for sound
and video i/o, whereas signal processing codes are done here in C.
..................Content has been hidden....................

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