c5d6c8a7e517a9d4a399211682926f4eed7ea310
[nit.git] / lib / ios / examples / hello_ios.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Simple iOS app with a single label
16 module hello_ios is
17 app_name "Hello iOS"
18 app_namespace "nit.app.hello_ios"
19 app_version(0, 5, git_revision)
20 end
21
22 import ios
23
24 redef class App
25 redef fun did_finish_launching_with_options
26 do
27 return app_delegate.hello_world
28 end
29 end
30
31 redef class AppDelegate
32
33 # Print and show "Hello World!"
34 private fun hello_world: Bool in "ObjC" `{
35
36 // Print to the console
37 NSLog(@"Hello World!");
38
39 // Display "Hello world!" on the screen
40 CGRect frame = [[UIScreen mainScreen] bounds];
41 self.window = [[UIWindow alloc] initWithFrame: frame];
42 self.window.backgroundColor = [UIColor whiteColor];
43
44 UILabel *label = [[UILabel alloc] init];
45 label.text = @"Hello World!";
46 label.center = CGPointMake(100, 100);
47 [label sizeToFit];
48
49 // As with `self.window` we must set a `rootViewController`
50 self.window.rootViewController = [[UIViewController alloc]initWithNibName:nil bundle:nil];
51 self.window.rootViewController.view = label;
52
53 [self.window addSubview: label];
54 [self.window makeKeyAndVisible];
55
56 return YES;
57 `}
58 end