FMCPlanner2/FMC Planner 2/ViewController.m
2016-03-20 14:26:52 +01:00

103 lines
3.1 KiB
Objective-C

//
// ViewController.m
// FMC Planner 2
//
// Created by Kilian Hofmann on 19.03.16.
// Copyright © 2016 Kilian Hofmann. All rights reserved.
//
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_alphaOn = true;
_alphabet = [[NSArray alloc]
initWithObjects:@"A", @"B", @"C", @"D", @"E", @"F", @"G", @"H", @"I",
@"J", @"K", @"L", @"M", @"N", @"O", @"P", @"Q", @"R",
@"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z", @"SP",
@"CLR", @"DEL", @"NUM", nil];
_numeric = [[NSArray alloc]
initWithObjects:@"1", @"2", @"3", @"", @"", @"", @"4", @"5", @"6",
@"", @"", @"", @"7", @"8", @"9", @"", @"", @"",
@".", @"0", @"/", @"", @"", @"", @"", @"", @"SP",
@"CLR", @"DEL", @"LET", nil];
// Round corners
_backdropKeys.layer.cornerRadius = 5;
_backdropKeys.layer.masksToBounds = YES;
_backdropScreen.layer.cornerRadius = 5;
_backdropScreen.layer.masksToBounds = YES;
for (UIButton *but in _Keys) {
but.layer.cornerRadius = 5;
but.layer.masksToBounds = YES;
}
// Set Font Size
if (self.view.frame.size.height == 480) {
for (UILabel *label in _ScreenLabels) {
label.font = [UIFont systemFontOfSize:14];
}
_Header.font = [UIFont systemFontOfSize:14];
_Scratchpad.font = [UIFont systemFontOfSize:14];
}
// Init Start Page
[self clearScreen];
_Header.text = @"START";
_Scratchpad.text = @"";
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)KeyTaps:(UIButton *)sender {
if ([sender.restorationIdentifier isEqualToString:@"Switch"]) {
_alphaOn = !_alphaOn;
[self switchKeyboard];
} else if ([sender.restorationIdentifier isEqualToString:@"Space"]) {
_Scratchpad.text = [_Scratchpad.text stringByAppendingString:@" "];
} else if ([sender.restorationIdentifier isEqualToString:@"Clear"]) {
if ([_Scratchpad.text isEqualToString:@"DELETE"]) {
_Scratchpad.text = @"";
} else if (_Scratchpad.text.length > 0) {
_Scratchpad.text =
[_Scratchpad.text substringToIndex:[_Scratchpad.text length] - 1];
}
} else if ([sender.restorationIdentifier isEqualToString:@"Delete"]) {
_Scratchpad.text = @"DELETE";
} else {
_Scratchpad.text =
[_Scratchpad.text stringByAppendingString:sender.titleLabel.text];
}
}
- (void)clearScreen {
for (UILabel *label in _ScreenLabels) {
label.text = @"";
}
_Scratchpad.text = @"";
_Header.text = @"";
}
- (void)switchKeyboard {
if (_alphaOn) {
for (int i = 0; i < _Keys.count; i++) {
[((UIButton *)_Keys[i]) setTitle:_alphabet[i]
forState:UIControlStateNormal];
[((UIButton *)_Keys[i]).titleLabel sizeToFit];
}
} else {
for (int i = 0; i < _Keys.count; i++) {
[((UIButton *)_Keys[i]) setTitle:_numeric[i]
forState:UIControlStateNormal];
[((UIButton *)_Keys[i]).titleLabel sizeToFit];
}
}
}
@end