d11ffcb00caad0a41633a1891aeda3c0646d8c22
[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
17
18 import ios
19
20 redef class App
21 redef fun did_finish_launching_with_options
22 do
23 return app_delegate.hello_world
24 end
25 end
26
27 redef class AppDelegate
28
29 # Print and show "Hello World!"
30 private fun hello_world: Bool in "ObjC" `{
31
32 // Print to the console
33 NSLog(@"Hello World!");
34
35 // Display "Hello world!" on the screen
36 recv.window = [[UIWindow alloc] initWithFrame:
37 [[UIScreen mainScreen] bounds]];
38 recv.window.backgroundColor = [UIColor whiteColor];
39
40 UILabel *label = [[UILabel alloc] init];
41 label.text = @"Hello World!";
42 label.center = CGPointMake(100, 100);
43 [label sizeToFit];
44
45 [recv.window addSubview: label];
46 [recv.window makeKeyAndVisible];
47
48 return YES;
49 `}
50 end