diff options
author | Grzegorz Adam Hankiewicz <gradha@imap.cc> | 2012-09-08 11:26:04 +0200 |
---|---|---|
committer | Grzegorz Adam Hankiewicz <gradha@imap.cc> | 2012-09-08 22:41:18 +0200 |
commit | b1ad04e30654264da13d84038dc24b551b619604 (patch) | |
tree | 72bf907eb6dd24ad6fb76771528ae6e7943db0b5 /examples/cross_calculator/ios/src/NRViewController.m | |
parent | 68fda81780c4eb835f9c46a1f3136e98c806af4c (diff) | |
download | Nim-b1ad04e30654264da13d84038dc24b551b619604.tar.gz |
Changes NIB to template and generates code manually for UI.
Diffstat (limited to 'examples/cross_calculator/ios/src/NRViewController.m')
-rw-r--r-- | examples/cross_calculator/ios/src/NRViewController.m | 168 |
1 files changed, 152 insertions, 16 deletions
diff --git a/examples/cross_calculator/ios/src/NRViewController.m b/examples/cross_calculator/ios/src/NRViewController.m index 03b2548ad..bd0df7d6b 100644 --- a/examples/cross_calculator/ios/src/NRViewController.m +++ b/examples/cross_calculator/ios/src/NRViewController.m @@ -10,22 +10,6 @@ @synthesize calculateButton = _calculateButton; @synthesize resultLabel = _resultLabel; -/** We need no special custom initialization for this example. - * Note that this example project has been made to deploy only on iOS 4.x - * upwards because the currently available Xcode tools are incapable of - * generating iOS 3.x backwards compatible NIB files. If your device is 3.x - * only you can replace the NIM with UI construction in code and everything - * else should be fine. - */ -- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil -{ - self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; - if (self) { - // Custom initialization - } - return self; -} - - (void)dealloc { [_aText release]; @@ -71,4 +55,156 @@ [self.bText resignFirstResponder]; } +/** Custom loadView method for backwards compatiblity. + * Unfortunately I've been unable to coerce Xcode 4.4 to generate nib files + * which are compatible with my trusty iOS 3.0 ipod touch so in order to be + * fully compatible for all devices we have to build the interface manually in + * code rather than through the keyed archivers provided by the interface + * builder. + * + * Rather than recreating the user interface manually in code the tool nib2obj + * was used on the xib file and slightly modified to fit the original property + * names. Which means here is a lot of garbage you would never write in real + * life. Please ignore the following "wall of code" for the purposes of + * learning Nimrod, this is all just because Apple can't be bothered to + * maintain backwards compatibility properly. + */ +- (void)loadView +{ + [super loadView]; + + self.calculateButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; + self.calculateButton.autoresizesSubviews = YES; + self.calculateButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin; + self.calculateButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; + self.calculateButton.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}"); + self.calculateButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; + self.calculateButton.frame = CGRectMake(193.0, 124.0, 107.0, 37.0); + self.calculateButton.tag = 5; + [self.calculateButton setTitle:@"Add!" forState:UIControlStateNormal]; + [self.calculateButton addTarget:self + action:@selector(calculateButtonTouched) + forControlEvents:UIControlEventTouchUpInside]; + + UILabel *label11 = [[UILabel alloc] initWithFrame:CGRectMake(20.0, 124.0, 60.0, 37.0)]; + label11.adjustsFontSizeToFitWidth = YES; + label11.autoresizesSubviews = YES; + label11.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin; + label11.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}"); + label11.frame = CGRectMake(20.0, 124.0, 60.0, 37.0); + label11.tag = 6; + label11.text = @"Result:"; + + UILabel *label4 = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 34.0)]; + label4.adjustsFontSizeToFitWidth = YES; + label4.autoresizesSubviews = YES; + label4.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin; + label4.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}"); + label4.frame = CGRectMake(0.0, 0.0, 320.0, 34.0); + label4.tag = 2; + label4.text = @"Nimrod Crossplatform Calculator"; + label4.textAlignment = UITextAlignmentCenter; + + UIButton *background_button = [UIButton buttonWithType:UIButtonTypeCustom]; + background_button.autoresizesSubviews = YES; + background_button.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin; + background_button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; + background_button.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}"); + background_button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; + background_button.frame = CGRectMake(0.0, -10.0, 320.0, 480.0); + background_button.tag = 1; + [background_button addTarget:self action:@selector(backgroundTouched) + forControlEvents:UIControlEventTouchDown]; + + self.resultLabel = [[[UILabel alloc] initWithFrame:CGRectMake(88.0, 124.0, 97.0, 37.0)] autorelease]; + self.resultLabel.adjustsFontSizeToFitWidth = YES; + self.resultLabel.autoresizesSubviews = YES; + self.resultLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin; + self.resultLabel.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}"); + self.resultLabel.frame = CGRectMake(88.0, 124.0, 97.0, 37.0); + self.resultLabel.tag = 7; + self.resultLabel.text = @""; + + self.aText = [[[UITextField alloc] initWithFrame:CGRectMake(193.0, 42.0, 107.0, 31.0)] autorelease]; + self.aText.adjustsFontSizeToFitWidth = YES; + self.aText.autocapitalizationType = UITextAutocapitalizationTypeNone; + self.aText.autocorrectionType = UITextAutocorrectionTypeDefault; + self.aText.autoresizesSubviews = YES; + self.aText.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin; + self.aText.borderStyle = UITextBorderStyleRoundedRect; + self.aText.clearButtonMode = UITextFieldViewModeWhileEditing; + self.aText.clearsOnBeginEditing = NO; + self.aText.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; + self.aText.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}"); + self.aText.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; + self.aText.enablesReturnKeyAutomatically = NO; + self.aText.frame = CGRectMake(193.0, 42.0, 107.0, 31.0); + self.aText.keyboardAppearance = UIKeyboardAppearanceDefault; + self.aText.keyboardType = UIKeyboardTypeNumberPad; + self.aText.placeholder = @"Integer"; + self.aText.returnKeyType = UIReturnKeyDefault; + self.aText.tag = 8; + self.aText.text = @""; + self.aText.textAlignment = UITextAlignmentCenter; + + UILabel *label7 = [[UILabel alloc] initWithFrame:CGRectMake(20.0, 42.0, 165.0, 31.0)]; + label7.adjustsFontSizeToFitWidth = YES; + label7.autoresizesSubviews = YES; + label7.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin; + label7.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}"); + label7.frame = CGRectMake(20.0, 42.0, 165.0, 31.0); + label7.tag = 3; + label7.text = @"Value A:"; + + UILabel *label8 = [[UILabel alloc] initWithFrame:CGRectMake(20.0, 81.0, 165.0, 31.0)]; + label8.adjustsFontSizeToFitWidth = YES; + label8.autoresizesSubviews = YES; + label8.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin; + label8.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}"); + label8.frame = CGRectMake(20.0, 81.0, 165.0, 31.0); + label8.tag = 4; + label8.text = @"Value B:"; + + self.bText = [[[UITextField alloc] + initWithFrame:CGRectMake(193.0, 81.0, 107.0, 31.0)] autorelease]; + self.bText.adjustsFontSizeToFitWidth = YES; + self.bText.autocapitalizationType = UITextAutocapitalizationTypeNone; + self.bText.autocorrectionType = UITextAutocorrectionTypeDefault; + self.bText.autoresizesSubviews = YES; + self.bText.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin; + self.bText.borderStyle = UITextBorderStyleRoundedRect; + self.bText.clearButtonMode = UITextFieldViewModeWhileEditing; + self.bText.clearsOnBeginEditing = NO; + self.bText.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; + self.bText.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}"); + self.bText.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; + self.bText.enablesReturnKeyAutomatically = NO; + self.bText.frame = CGRectMake(193.0, 81.0, 107.0, 31.0); + self.bText.keyboardAppearance = UIKeyboardAppearanceDefault; + self.bText.keyboardType = UIKeyboardTypeNumberPad; + self.bText.placeholder = @"Integer"; + self.bText.returnKeyType = UIReturnKeyDefault; + self.bText.tag = 9; + self.bText.text = @""; + self.bText.textAlignment = UITextAlignmentCenter; + + self.view.frame = CGRectMake(0.0, 20.0, 320.0, 460.0); + self.view.autoresizesSubviews = YES; + self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + self.view.backgroundColor = [UIColor colorWithWhite:1.000 alpha:1.000]; + self.view.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}"); + self.view.frame = CGRectMake(0.0, 20.0, 320.0, 460.0); + self.view.tag = 0; + + [self.view addSubview:background_button]; + [self.view addSubview:label4]; + [self.view addSubview:label7]; + [self.view addSubview:label8]; + [self.view addSubview:self.calculateButton]; + [self.view addSubview:label11]; + [self.view addSubview:self.resultLabel]; + [self.view addSubview:self.aText]; + [self.view addSubview:self.bText]; +} + @end |