Skip to content

Commit 72f0ebc

Browse files
author
Marco Abundo
committed
Reverted to Objective-C
1 parent 0933383 commit 72f0ebc

18 files changed

Lines changed: 525 additions & 242 deletions

SLTDoubleTapSegmentedControl.xcodeproj/project.pbxproj

Lines changed: 182 additions & 50 deletions
Large diffs are not rendered by default.

SLTDoubleTapSegmentedControl/Images.xcassets/AppIcon.appiconset/Contents.json

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
{
22
"images" : [
3-
{
4-
"idiom" : "iphone",
5-
"size" : "20x20",
6-
"scale" : "2x"
7-
},
8-
{
9-
"idiom" : "iphone",
10-
"size" : "20x20",
11-
"scale" : "3x"
12-
},
133
{
144
"idiom" : "iphone",
155
"size" : "29x29",
@@ -40,16 +30,6 @@
4030
"size" : "60x60",
4131
"scale" : "3x"
4232
},
43-
{
44-
"idiom" : "ipad",
45-
"size" : "20x20",
46-
"scale" : "1x"
47-
},
48-
{
49-
"idiom" : "ipad",
50-
"size" : "20x20",
51-
"scale" : "2x"
52-
},
5333
{
5434
"idiom" : "ipad",
5535
"size" : "29x29",
@@ -79,16 +59,6 @@
7959
"idiom" : "ipad",
8060
"size" : "76x76",
8161
"scale" : "2x"
82-
},
83-
{
84-
"idiom" : "ipad",
85-
"size" : "83.5x83.5",
86-
"scale" : "2x"
87-
},
88-
{
89-
"idiom" : "ios-marketing",
90-
"size" : "1024x1024",
91-
"scale" : "1x"
9262
}
9363
],
9464
"info" : {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2014 shrtlist
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
@interface SLTAppDelegate : UIResponder <UIApplicationDelegate>
18+
19+
@property (strong, nonatomic) UIWindow *window;
20+
21+
@end
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2014 shrtlist
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import "SLTAppDelegate.h"
18+
#import "SLTViewController.h"
19+
20+
@implementation SLTAppDelegate
21+
22+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
23+
{
24+
// Override point for customization after application launch.
25+
26+
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
27+
28+
SLTViewController *viewController = [[SLTViewController alloc] initWithNibName:@"SLTViewController" bundle:nil];
29+
30+
[self.window setRootViewController:viewController];
31+
[self.window makeKeyAndVisible];
32+
33+
return YES;
34+
}
35+
36+
@end

SLTDoubleTapSegmentedControl/SLTAppDelegate.swift

Lines changed: 0 additions & 36 deletions
This file was deleted.

SLTDoubleTapSegmentedControl/SLTDoubleTapSegmentedControl-Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<key>CFBundlePackageType</key>
1818
<string>APPL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>1.1</string>
20+
<string>1.0</string>
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleVersion</key>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// Prefix header
3+
//
4+
// The contents of this file are implicitly included at the beginning of every source file.
5+
//
6+
7+
#import <Availability.h>
8+
9+
#ifndef __IPHONE_3_0
10+
#warning "This project uses features only available in iOS SDK 3.0 and later."
11+
#endif
12+
13+
#ifdef __OBJC__
14+
#import <UIKit/UIKit.h>
15+
#import <Foundation/Foundation.h>
16+
#endif
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2014 shrtlist
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// Double-tap segmented control. Each segment functions as a discrete double-tap button.
18+
// Credit: http://stackoverflow.com/questions/17652773/how-to-deselect-a-segment-in-segmented-control-button-permanently-till-its-click?lq=1
19+
20+
@import UIKit;
21+
22+
@interface SLTDoubleTapSegmentedControl : UISegmentedControl
23+
24+
- (void)setTintColor:(UIColor *)tintColor forSegmentAtIndex:(NSUInteger)segment;
25+
26+
@end
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* Copyright 2014 shrtlist
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import "SLTDoubleTapSegmentedControl.h"
18+
19+
@implementation SLTDoubleTapSegmentedControl
20+
21+
#pragma mark - Public method
22+
23+
- (void)setTintColor:(UIColor *)tintColor forSegmentAtIndex:(NSUInteger)segment
24+
{
25+
NSString *title = [self titleForSegmentAtIndex:segment];
26+
27+
if (title)
28+
{
29+
UIFont *font = [UIFont systemFontOfSize:12.0f];
30+
NSDictionary *attributes = @{NSFontAttributeName:font,
31+
NSForegroundColorAttributeName:tintColor};
32+
33+
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:title attributes:attributes];
34+
35+
UIImage *image = [self imageFromAttributedString:attributedString];
36+
37+
[self setImage:image forSegmentAtIndex:segment];
38+
}
39+
}
40+
41+
#pragma mark - Private methods
42+
43+
- (UIImage *)imageFromAttributedString:(NSAttributedString *)text
44+
{
45+
UIGraphicsBeginImageContextWithOptions(text.size, NO, 0.0);
46+
47+
// draw in context
48+
[text drawAtPoint:CGPointMake(0.0, 0.0)];
49+
50+
// transfer image
51+
UIImage *image = [UIGraphicsGetImageFromCurrentImageContext() imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
52+
UIGraphicsEndImageContext();
53+
54+
return image;
55+
}
56+
57+
+ (BOOL)isIOS7
58+
{
59+
static BOOL isIOS7 = NO;
60+
static dispatch_once_t onceToken;
61+
dispatch_once(&onceToken, ^{
62+
NSInteger deviceSystemMajorVersion = [[[[[UIDevice currentDevice] systemVersion] componentsSeparatedByString:@"."] objectAtIndex:0] integerValue];
63+
if (deviceSystemMajorVersion >= 7) {
64+
isIOS7 = YES;
65+
}
66+
else {
67+
isIOS7 = NO;
68+
}
69+
});
70+
return isIOS7;
71+
}
72+
73+
#pragma mark - Custom touch handling
74+
75+
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
76+
{
77+
NSInteger previousSelectedSegmentIndex = self.selectedSegmentIndex;
78+
79+
[super touchesBegan:touches withEvent:event];
80+
81+
if (![[self class] isIOS7])
82+
{
83+
// before iOS7 the segment is selected in touchesBegan
84+
if (previousSelectedSegmentIndex == self.selectedSegmentIndex)
85+
{
86+
// Clear the segmented control
87+
[self setSelectedSegmentIndex:UISegmentedControlNoSegment];
88+
89+
// if the selectedSegmentIndex before the selection process is equal to the selectedSegmentIndex
90+
// after the selection process the superclass won't send a UIControlEventValueChanged event.
91+
// So we have to do this ourselves.
92+
[self sendActionsForControlEvents:UIControlEventValueChanged];
93+
}
94+
}
95+
}
96+
97+
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
98+
{
99+
NSInteger previousSelectedSegmentIndex = self.selectedSegmentIndex;
100+
101+
[super touchesEnded:touches withEvent:event];
102+
103+
if ([[self class] isIOS7])
104+
{
105+
// on iOS7 the segment is selected in touchesEnded
106+
if (previousSelectedSegmentIndex == self.selectedSegmentIndex)
107+
{
108+
// Clear the segmented control
109+
[self setSelectedSegmentIndex:UISegmentedControlNoSegment];
110+
111+
// if the selectedSegmentIndex before the selection process is equal to the selectedSegmentIndex
112+
// after the selection process the superclass won't send a UIControlEventValueChanged event.
113+
// So we have to do this ourselves.
114+
[self sendActionsForControlEvents:UIControlEventValueChanged];
115+
}
116+
}
117+
}
118+
119+
@end

0 commit comments

Comments
 (0)