129 lines
3.7 KiB
Objective-C
129 lines
3.7 KiB
Objective-C
//
|
|
// ViewControllerScreen.m
|
|
// FMC Planner 2
|
|
//
|
|
// Created by Kilian Hofmann on 20.03.16.
|
|
// Copyright © 2016 Kilian Hofmann. All rights reserved.
|
|
//
|
|
|
|
#import "ViewControllerScreen.h"
|
|
|
|
@implementation ViewControllerScreen
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
|
|
// Do any additional setup after loading the view.
|
|
// Init Start Page
|
|
[self clearScreen];
|
|
_Header.text = @"START";
|
|
_Scratchpad.text = @"";
|
|
|
|
// Tap gesture shit
|
|
for (UILabel *label in _LSK) {
|
|
label.adjustsFontSizeToFitWidth = YES;
|
|
label.userInteractionEnabled = YES;
|
|
UITapGestureRecognizer *reg =
|
|
[[UITapGestureRecognizer alloc] initWithTarget:self
|
|
action:@selector(enterLSK:)];
|
|
[reg setNumberOfTapsRequired:1];
|
|
[reg setNumberOfTouchesRequired:1];
|
|
[label addGestureRecognizer:reg];
|
|
}
|
|
}
|
|
|
|
- (void)viewDidAppear:(BOOL)animated {
|
|
[self loadScreen:@"Menu"];
|
|
}
|
|
|
|
- (void)viewDidLayoutSubviews {
|
|
_FrameHeight.constant = self.view.frame.size.height / 14.5;
|
|
// Size and LineBreak
|
|
|
|
_Header.font = [self findAdaptiveFontForUILabelSize:_Header.frame.size
|
|
withMinimumSize:5
|
|
withMod:0.7];
|
|
_Header.adjustsFontSizeToFitWidth = YES;
|
|
_Scratchpad.font = [self findAdaptiveFontForUILabelSize:_Scratchpad.frame.size
|
|
withMinimumSize:5
|
|
withMod:0.7];
|
|
_Scratchpad.adjustsFontSizeToFitWidth = YES;
|
|
for (UILabel *label in _LSK) {
|
|
label.font = [self findAdaptiveFontForUILabelSize:_Header.frame.size
|
|
withMinimumSize:5
|
|
withMod:0.6];
|
|
}
|
|
}
|
|
|
|
- (void)clearScreen {
|
|
for (UILabel *label in _LSK) {
|
|
label.text = @"";
|
|
}
|
|
_Scratchpad.text = @"";
|
|
_Header.text = @"";
|
|
}
|
|
|
|
- (void)enterLSK:(UITapGestureRecognizer *)tapReg {
|
|
if ([_Scratchpad.text isEqualToString:@"DELETE"]) {
|
|
((UILabel *)tapReg.view).text = @"";
|
|
} else {
|
|
((UILabel *)tapReg.view).text = _Scratchpad.text;
|
|
}
|
|
_Scratchpad.text = @"";
|
|
}
|
|
|
|
- (UIFont *)findAdaptiveFontForUILabelSize:(CGSize)labelSize
|
|
withMinimumSize:(NSInteger)minSize
|
|
withMod:(float)mod {
|
|
UIFont *tempFont = nil;
|
|
NSString *testString =
|
|
@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
|
|
NSInteger tempMin = minSize / mod;
|
|
NSInteger tempMax = 256;
|
|
NSInteger mid = 0;
|
|
NSInteger difference = 0;
|
|
|
|
while (tempMin <= tempMax) {
|
|
mid = tempMin + (tempMax - tempMin) / 2;
|
|
tempFont = [UIFont systemFontOfSize:mid];
|
|
difference =
|
|
labelSize.height / mod -
|
|
[testString
|
|
sizeWithAttributes:[NSDictionary
|
|
dictionaryWithObject:tempFont
|
|
forKey:NSFontAttributeName]]
|
|
.height;
|
|
|
|
if (mid == tempMin || mid == tempMax) {
|
|
if (difference < 0) {
|
|
return [UIFont systemFontOfSize:(mid - 1)];
|
|
}
|
|
|
|
return [UIFont systemFontOfSize:mid];
|
|
}
|
|
|
|
if (difference < 0) {
|
|
tempMax = mid - 1;
|
|
} else if (difference > 0) {
|
|
tempMin = mid + 1;
|
|
} else {
|
|
return [UIFont systemFontOfSize:mid];
|
|
}
|
|
}
|
|
|
|
return [UIFont systemFontOfSize:mid];
|
|
}
|
|
|
|
- (void)loadScreen:(NSString *)screenName {
|
|
_Header.text = screenName;
|
|
NSArray *screen = [[NSArray alloc]
|
|
initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:screenName
|
|
ofType:@"plist"]];
|
|
for (int i = 0; i < _Desc.count; i++) {
|
|
((UILabel *)_Desc[i]).text = [NSString stringWithFormat:@"%@\n", screen[i]];
|
|
}
|
|
}
|
|
|
|
@end
|