-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlatPrefs.xm
201 lines (170 loc) · 8.2 KB
/
FlatPrefs.xm
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#import "Header.h"
%group Prefs
%hook PSViewController
-(id)_navControllerToCreateManagedSearchPaletteForNavController:(id)arg1 {
return NULL;
}
%end
%hook PSListController
%property (nonatomic, strong) UIImage *shadowImage;
-(UINavigationController *)navigationController {
UINavigationController *original = %orig;
if (!self.shadowImage) {
CGSize size = CGSizeMake(1, 8);
UIGraphicsBeginImageContextWithOptions(size, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
size_t gradientNumberOfLocations = 2;
CGFloat gradientLocations[2] = { 0.0, 1.0 };
CGFloat gradientComponents[8] = { 0, 0, 0, 0.15, 0, 0, 0, 0};
CGGradientRef gradient = CGGradientCreateWithColorComponents (colorspace, gradientComponents, gradientLocations, gradientNumberOfLocations);
CGContextDrawLinearGradient(context, gradient, CGPointMake(0, 0), CGPointMake(0, size.height), 0);
self.shadowImage = UIGraphicsGetImageFromCurrentImageContext();
CGGradientRelease(gradient);
CGColorSpaceRelease(colorspace);
UIGraphicsEndImageContext();
}
[original.navigationBar setShadowImage:self.shadowImage];
return original;
}
-(PSTableCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index {
PSTableCell *cell = %orig;
if (index.row == 0) {
cell.shadowView.layer.shadowOffset = CGSizeMake(0, 2);
cell.shadowView.layer.cornerRadius = kCellRadius;
cell.layer.cornerRadius = kCellRadius;
if ([self rowsForGroup:index.section] == 1) {
cell.behaviour = shadowViewBehaviourLonly;
cell.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner | kCALayerMaxXMaxYCorner | kCALayerMinXMaxYCorner;
cell.shadowView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner | kCALayerMaxXMaxYCorner | kCALayerMinXMaxYCorner;
}else{
cell.behaviour = shadowViewBehaviourTop;
cell.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
cell.shadowView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
}
}else if (index.row == [self rowsForGroup:index.section] - 1) {
cell.behaviour = shadowViewBehaviourBottom;
cell.shadowView.layer.shadowOffset = CGSizeMake(0, 2);
cell.shadowView.layer.cornerRadius = kCellRadius;
cell.layer.cornerRadius = kCellRadius;
cell.layer.maskedCorners = kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner;
cell.shadowView.layer.maskedCorners = kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner;
}else{
cell.behaviour = shadowViewBehaviourCenter;
cell.shadowView.layer.shadowOffset = CGSizeMake(0, 0);
cell.shadowView.layer.cornerRadius = 0;
cell.layer.cornerRadius = 0;
}
cell.shadowView.layer.shadowOpacity = 0.9;
cell.shadowView.layer.shadowRadius = 4;
cell.shadowView.layer.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.3].CGColor;
return cell;
}
-(double)tableView:(UITableView *)table heightForHeaderInSection:(long long)section {
if ([self tableView:table titleForHeaderInSection:section] || [self tableView:table viewForHeaderInSection:section]) {
return %orig;
}
if (section != 0) {
return kSectionDistance / 2.0;
}else{
return kSectionDistance * 2;
}
return kSectionDistance;
}
-(double)tableView:(UITableView *)table heightForFooterInSection:(long long)section {
if ([self tableView:table titleForFooterInSection:section] || [self tableView:table viewForFooterInSection:section]) {
return %orig;
}
if (section != [self numberOfSectionsInTableView:table] - 1) {
return kSectionDistance / 2.0;
}
return kSectionDistance;
}
-(id)tableView:(id)arg1 viewForHeaderInSection:(long long)arg2 {
UITableViewHeaderFooterView *original = %orig;
[original setBackgroundColor:[UIColor clearColor]];
if ([original isKindOfClass:NSClassFromString(@"UITableViewHeaderFooterView")]) {
[original _setBackgroundViewColor:[UIColor clearColor]];
}
return original;
}
-(id)tableView:(id)arg1 viewForFooterInSection:(long long)arg2 {
UITableViewHeaderFooterView *original = %orig;
[original setBackgroundColor:[UIColor clearColor]];
if ([original isKindOfClass:NSClassFromString(@"UITableViewHeaderFooterView")]) {
[original _setBackgroundViewColor:[UIColor clearColor]];
}
return original;
}
%end
%hook PSTableCell
%property (nonatomic, strong) UIView *shadowMaskView;
%property (nonatomic, strong) UIView *shadowView;
%property (nonatomic, assign) shadowViewBehaviour behaviour;
-(id)initWithStyle:(long long)arg1 reuseIdentifier:(id)arg2 specifier:(id)arg3 {
if ((self = %orig)) {
self.behaviour = shadowViewBehaviourCenter;
self.shadowMaskView = [[UIView alloc] init];
self.shadowMaskView.layer.masksToBounds = YES;
self.shadowMaskView.backgroundColor = [UIColor clearColor];
self.shadowView = [[UIView alloc] init];
self.shadowView.backgroundColor = [UIColor whiteColor];
[self.shadowMaskView addSubview:self.shadowView];
[self addSubview:self.shadowMaskView];
}
return self;
}
-(void)setFrame:(CGRect)frame {
%orig(CGRectMake(kCellIndentation, frame.origin.y, frame.size.width - kCellIndentation * 2, frame.size.height));
}
-(void)layoutSubviews {
%orig;
if (self.behaviour == shadowViewBehaviourLonly) {
self.shadowMaskView.frame = self.bounds;
self.shadowMaskView.layer.masksToBounds = NO;
self.shadowView.frame = self.bounds;
}else if (self.behaviour == shadowViewBehaviourTop) {
self.shadowMaskView.layer.masksToBounds = YES;
self.shadowMaskView.frame = CGRectMake(-kCellIndentation, -kSectionDistance, self.frame.size.width + kCellIndentation * 2, self.frame.size.height + kSectionDistance);
self.shadowView.frame = CGRectMake(kCellIndentation, kSectionDistance, self.frame.size.width, self.shadowMaskView.frame.size.height - kSectionDistance + kCellIndentation * 2);
}else if (self.behaviour == shadowViewBehaviourCenter) {
self.shadowMaskView.layer.masksToBounds = YES;
self.shadowMaskView.frame = CGRectMake(-kCellIndentation, 0, self.frame.size.width + kCellIndentation * 2, self.frame.size.height);
self.shadowView.frame = CGRectMake(kCellIndentation, -kCellIndentation*2, self.frame.size.width, self.shadowMaskView.frame.size.height + kCellIndentation * 4);
}else{
self.shadowMaskView.layer.masksToBounds = YES;
self.shadowMaskView.frame = CGRectMake(-kCellIndentation, 0, self.frame.size.width + kCellIndentation * 2, self.frame.size.height + kSectionDistance);
self.shadowView.frame = CGRectMake(kCellIndentation, -kCellIndentation * 2, self.frame.size.width, self.shadowMaskView.frame.size.height - kSectionDistance + kCellIndentation * 2);
}
self.shadowView.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:self.shadowView.bounds cornerRadius:self.layer.cornerRadius].CGPath;
[self sendSubviewToBack:self.shadowMaskView];
}
-(BOOL)_shouldHideSeparator {
return YES;
}
-(void)showSelectedBackgroundView:(BOOL)arg1 animated:(BOOL)arg2 {
if (arg1) {
self.shadowView.backgroundColor = [UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0];
self.textLabel.textColor = [UIColor whiteColor];
self.detailTextLabel.textColor = [UIColor colorWithWhite:1.0 alpha:0.8];
}else{
self.shadowView.backgroundColor = [UIColor whiteColor];
self.textLabel.textColor = [UIColor blackColor];
self.detailTextLabel.textColor = [UIColor colorWithRed:142.0/255.0 green:142.0/255.0 blue:147.0/255.0 alpha:1.0];
}
}
%end
%hook PSSwitchTableCell
-(UISwitch *)newControl {
UISwitch *original = %orig;
[original setOnTintColor:[UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0]];
return original;
}
%end
%end
%ctor {
NSString *bundleIdentifier = [NSBundle mainBundle].bundleIdentifier;
if ([bundleIdentifier isEqualToString:@"com.apple.Preferences"]) {
%init(Prefs);
}
}