109 lines
3.4 KiB
Objective-C
109 lines
3.4 KiB
Objective-C
//
|
|
// SharedDecleartions.m
|
|
// FMC Planner 2
|
|
//
|
|
// Created by Kilian Hofmann on 23.03.16.
|
|
// Copyright © 2016 Kilian Hofmann. All rights reserved.
|
|
//
|
|
|
|
#import "SharedDeclerations.h"
|
|
|
|
@implementation SharedDeclerations
|
|
|
|
NSString *const FMCNEXTRTEPAGE = @"NEXTRTEPAGE";
|
|
NSString *const FMCFIRSTRTEPAGE = @"FIRSTRTEPAGE";
|
|
|
|
NSString *const INVALID = @"INVALID ENTRY";
|
|
NSString *const NOTREADY = @"NAV DATA NOT READY";
|
|
|
|
NSString *const DropboxErrorDomain = @"com.weebly.alikja.FMC";
|
|
NSString *const DropboxErrorUserInfo = @"error_summary";
|
|
|
|
#pragma mark - Adaptive font size method
|
|
|
|
+ (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:@{
|
|
NSFontAttributeName : tempFont
|
|
}].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];
|
|
}
|
|
|
|
#pragma mark - Savepath method
|
|
|
|
+ (NSString *)savePathForFile:(NSString *)file
|
|
{
|
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
|
|
NSUserDomainMask, YES);
|
|
NSString *documentsPath = paths[0];
|
|
return [documentsPath
|
|
stringByAppendingString:[NSString stringWithFormat:@"/%@", file]];
|
|
}
|
|
|
|
#pragma mark - Alert for handling displaying Error Messages.
|
|
|
|
+ (void)presentErrorAlert:(NSError *)error
|
|
presenter:(UIViewController *)presenter
|
|
{
|
|
if (presenter != nil) {
|
|
if ([UIAlertController class]) {
|
|
UIAlertController *alert = [UIAlertController
|
|
alertControllerWithTitle:@"Error"
|
|
message:error.localizedDescription
|
|
preferredStyle:UIAlertControllerStyleActionSheet];
|
|
UIAlertAction *defaultAction =
|
|
[UIAlertAction actionWithTitle:@"OK"
|
|
style:UIAlertActionStyleCancel
|
|
handler:nil];
|
|
[alert addAction:defaultAction];
|
|
|
|
[presenter presentViewController:alert animated:YES completion:nil];
|
|
}
|
|
else {
|
|
UIAlertView *alert =
|
|
[[UIAlertView alloc] initWithTitle:@"Error"
|
|
message:error.localizedDescription
|
|
delegate:nil
|
|
cancelButtonTitle:@"Cancel"
|
|
otherButtonTitles:nil];
|
|
[alert show];
|
|
}
|
|
}
|
|
}
|
|
|
|
@end
|