forked from arichornlover/uYouEnhanced
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColourOptionsController2.m
72 lines (53 loc) · 3.14 KB
/
ColourOptionsController2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#import "ColourOptionsController2.h"
#import "uYouPlus.h"
@interface ColourOptionsController2 ()
@end
@implementation ColourOptionsController2
- (void)loadView {
[super loadView];
self.title = @"Custom Tint Color";
UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStylePlain target:self action:@selector(close)];
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(save)];
self.navigationItem.rightBarButtonItems = @[closeButton, saveButton];
UIBarButtonItem *resetButton = [[UIBarButtonItem alloc] initWithTitle:@"Reset" style:UIBarButtonItemStylePlain target:self action:@selector(reset)];
self.navigationItem.leftBarButtonItem = resetButton;
self.supportsAlpha = NO;
NSData *lcmColorData = [[NSUserDefaults standardUserDefaults] objectForKey:@"kCustomUIColor"];
NSKeyedUnarchiver *lcmUnarchiver = [[NSKeyedUnarchiver alloc] initForReadingFromData:lcmColorData error:nil];
[lcmUnarchiver setRequiresSecureCoding:NO];
UIColor *color = [lcmUnarchiver decodeObjectForKey:NSKeyedArchiveRootObjectKey];
self.selectedColor = color;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
CGFloat scale = MIN(self.view.bounds.size.width / 768, self.view.bounds.size.height / 1024);
self.view.transform = CGAffineTransformMakeScale(scale, scale);
}
}
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad && UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
CGFloat scale = MIN(size.width / 768, size.height / 1024);
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
self.view.transform = CGAffineTransformMakeScale(scale, scale);
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
}];
}
}
@end
@implementation ColourOptionsController2(Privates)
- (void)close {
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
- (void)save {
NSData *lcmColorData = [NSKeyedArchiver archivedDataWithRootObject:self.selectedColor requiringSecureCoding:nil error:nil];
[[NSUserDefaults standardUserDefaults] setObject:lcmColorData forKey:@"kCustomUIColor"];
[[NSUserDefaults standardUserDefaults] synchronize];
UIAlertController *alertSaved = [UIAlertController alertControllerWithTitle:@"Color Saved" message:nil preferredStyle:UIAlertControllerStyleAlert];
[alertSaved addAction:[UIAlertAction actionWithTitle:@"Okay" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}]];
[self presentViewController:alertSaved animated:YES completion:nil];
}
- (void)reset {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"kCustomUIColor"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
@end