Skip to content

Commit ffb3ad5

Browse files
committed
Added example for using with Swift.
Made APIs more Swift friendly.
1 parent 50216aa commit ffb3ad5

File tree

13 files changed

+510
-98
lines changed

13 files changed

+510
-98
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44

55
---
66

7+
## [1.4.8](https://github.com/DavydLiu/DLRadioButton/releases/tag/1.4.8) (04/10/2016)
8+
* Added example for using with Swift.
9+
* Made APIs more Swift friendly.
10+
11+
712
## [1.4.7](https://github.com/DavydLiu/DLRadioButton/releases/tag/1.4.7) (04/02/2016)
813
* Added support for RTL interface layout.
914
* Updated API comments.

DLRadioButton.podspec.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "DLRadioButton",
3-
"version": "1.4.7",
3+
"version": "1.4.8",
44
"summary": "A highly customizable Radio Button for iOS",
55
"description": "A highly customizable Radio Button for iOS.\n\n* Buttons are drew by UIBezierPath, customize it however you want.\n* You can also use pictures to indicate buttons' selection state.\n",
66
"homepage": "https://github.com/DavydLiu/DLRadioButton",
@@ -17,7 +17,7 @@
1717
},
1818
"source": {
1919
"git": "https://github.com/DavydLiu/DLRadioButton.git",
20-
"tag": "1.4.7"
20+
"tag": "1.4.8"
2121
},
2222
"source_files": "DLRadioButton/**/*.{h,m}",
2323
"exclude_files": "Classes/Exclude",

DLRadioButton.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@
300300
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
301301
GCC_WARN_UNUSED_FUNCTION = YES;
302302
GCC_WARN_UNUSED_VARIABLE = YES;
303-
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
303+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
304304
MTL_ENABLE_DEBUG_INFO = YES;
305305
ONLY_ACTIVE_ARCH = YES;
306306
SDKROOT = iphoneos;
@@ -342,7 +342,7 @@
342342
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
343343
GCC_WARN_UNUSED_FUNCTION = YES;
344344
GCC_WARN_UNUSED_VARIABLE = YES;
345-
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
345+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
346346
MTL_ENABLE_DEBUG_INFO = NO;
347347
SDKROOT = iphoneos;
348348
TARGETED_DEVICE_FAMILY = "1,2";

DLRadioButton/DLRadioButton.h

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,35 @@
66
IB_DESIGNABLE
77
@interface DLRadioButton : UIButton
88

9+
#pragma mark - Access buttons
10+
11+
/**
12+
* Finds out selected button in same group.
13+
*
14+
* @return Selected button.
15+
*/
16+
- (nullable DLRadioButton *)selectedButton;
17+
18+
/**
19+
* Finds out selected buttons in same group, use it only if multiple selection is enabled.
20+
*
21+
* @return Selected buttons.
22+
*/
23+
- (nonnull NSArray<DLRadioButton *> *)selectedButtons;
24+
925
/**
1026
* Container for holding other buttons in same group.
1127
*/
12-
@property (nonatomic) IBOutletCollection(DLRadioButton) NSArray *otherButtons;
28+
@property (nonnull, nonatomic) IBOutletCollection(DLRadioButton) NSArray<DLRadioButton *> *otherButtons;
29+
30+
/**
31+
* Clears selection for other buttons in in same group.
32+
*/
33+
- (void)deselectOtherButtons;
1334

35+
#pragma mark - Customization
36+
37+
NS_ASSUME_NONNULL_BEGIN
1438
/**
1539
* Size of icon, default is kDefaulIconSize.
1640
*/
@@ -66,24 +90,6 @@ IB_DESIGNABLE
6690
* Whether enable multiple selection, default is NO.
6791
*/
6892
@property (nonatomic, getter = isMultipleSelectionEnabled) BOOL multipleSelectionEnabled;
69-
70-
/**
71-
* Finds out selected button in same group.
72-
*
73-
* @return Selected button.
74-
*/
75-
- (DLRadioButton *)selectedButton;
76-
77-
/**
78-
* Finds out selected buttons in same group, use it only if multiple selection is enabled.
79-
*
80-
* @return Selected buttons.
81-
*/
82-
- (NSArray *)selectedButtons;
83-
84-
/**
85-
* Clears selection for other buttons in in same group.
86-
*/
87-
- (void)deselectOtherButtons;
93+
NS_ASSUME_NONNULL_END
8894

8995
@end
0 Bytes
Binary file not shown.

Example/DLRadioButton.framework/Headers/DLRadioButton.h

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,35 @@
66
IB_DESIGNABLE
77
@interface DLRadioButton : UIButton
88

9+
#pragma mark - Access buttons
10+
11+
/**
12+
* Finds out selected button in same group.
13+
*
14+
* @return Selected button.
15+
*/
16+
- (nullable DLRadioButton *)selectedButton;
17+
18+
/**
19+
* Finds out selected buttons in same group, use it only if multiple selection is enabled.
20+
*
21+
* @return Selected buttons.
22+
*/
23+
- (nonnull NSArray<DLRadioButton *> *)selectedButtons;
24+
925
/**
1026
* Container for holding other buttons in same group.
1127
*/
12-
@property (nonatomic) IBOutletCollection(DLRadioButton) NSArray *otherButtons;
28+
@property (nonnull, nonatomic) IBOutletCollection(DLRadioButton) NSArray<DLRadioButton *> *otherButtons;
29+
30+
/**
31+
* Clears selection for other buttons in in same group.
32+
*/
33+
- (void)deselectOtherButtons;
1334

35+
#pragma mark - Customization
36+
37+
NS_ASSUME_NONNULL_BEGIN
1438
/**
1539
* Size of icon, default is kDefaulIconSize.
1640
*/
@@ -66,24 +90,6 @@ IB_DESIGNABLE
6690
* Whether enable multiple selection, default is NO.
6791
*/
6892
@property (nonatomic, getter = isMultipleSelectionEnabled) BOOL multipleSelectionEnabled;
69-
70-
/**
71-
* Finds out selected button in same group.
72-
*
73-
* @return Selected button.
74-
*/
75-
- (DLRadioButton *)selectedButton;
76-
77-
/**
78-
* Finds out selected buttons in same group, use it only if multiple selection is enabled.
79-
*
80-
* @return Selected buttons.
81-
*/
82-
- (NSArray *)selectedButtons;
83-
84-
/**
85-
* Clears selection for other buttons in in same group.
86-
*/
87-
- (void)deselectOtherButtons;
93+
NS_ASSUME_NONNULL_END
8894

8995
@end

Example/DLRadioButton.framework/_CodeSignature/CodeResources

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<dict>
77
<key>Headers/DLRadioButton.h</key>
88
<data>
9-
AUTpUW+3DpeB/74Awfr3kVxsj5U=
9+
AxrEoeOQUM+yJB38xuZlF8jcNuw=
1010
</data>
1111
<key>Info.plist</key>
1212
<data>
@@ -21,7 +21,7 @@
2121
<dict>
2222
<key>Headers/DLRadioButton.h</key>
2323
<data>
24-
AUTpUW+3DpeB/74Awfr3kVxsj5U=
24+
AxrEoeOQUM+yJB38xuZlF8jcNuw=
2525
</data>
2626
<key>Modules/module.modulemap</key>
2727
<data>

Example/DLRadioButtonExample.xcodeproj/project.pbxproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
63B875781CB047AB00AE8E98 /* DLRadioButton.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 63B875771CB047AB00AE8E98 /* DLRadioButton.framework */; };
1111
63B875791CB0481900AE8E98 /* DLRadioButton.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 63B875771CB047AB00AE8E98 /* DLRadioButton.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
12+
63B8757B1CBAB95800AE8E98 /* DemoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63B8757A1CBAB95800AE8E98 /* DemoViewController.swift */; };
1213
63C933161B48EB1C009DD715 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 63C933151B48EB1C009DD715 /* Images.xcassets */; };
1314
D1BE3A0319A7D263004BD3F5 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D1BE3A0219A7D263004BD3F5 /* Foundation.framework */; };
1415
D1BE3A0519A7D263004BD3F5 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D1BE3A0419A7D263004BD3F5 /* CoreGraphics.framework */; };
@@ -36,6 +37,7 @@
3637

3738
/* Begin PBXFileReference section */
3839
63B875771CB047AB00AE8E98 /* DLRadioButton.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = DLRadioButton.framework; sourceTree = "<group>"; };
40+
63B8757A1CBAB95800AE8E98 /* DemoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DemoViewController.swift; sourceTree = "<group>"; };
3941
63C933151B48EB1C009DD715 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
4042
D1BE39FF19A7D263004BD3F5 /* DLRadioButtonExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DLRadioButtonExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
4143
D1BE3A0219A7D263004BD3F5 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@@ -101,10 +103,11 @@
101103
D1BE3A1119A7D263004BD3F5 /* DLAppDelegate.h */,
102104
D1BE3A1219A7D263004BD3F5 /* DLAppDelegate.m */,
103105
63C933151B48EB1C009DD715 /* Images.xcassets */,
104-
D1BE3A0919A7D263004BD3F5 /* Supporting Files */,
105106
D1BE3A3519AB683D004BD3F5 /* Main.storyboard */,
106107
D1BE3A3719AB7000004BD3F5 /* DLDemoViewController.h */,
107108
D1BE3A3819AB7000004BD3F5 /* DLDemoViewController.m */,
109+
63B8757A1CBAB95800AE8E98 /* DemoViewController.swift */,
110+
D1BE3A0919A7D263004BD3F5 /* Supporting Files */,
108111
);
109112
path = DLRadioButtonExample;
110113
sourceTree = "<group>";
@@ -148,6 +151,7 @@
148151
isa = PBXProject;
149152
attributes = {
150153
CLASSPREFIX = DL;
154+
LastSwiftUpdateCheck = 0730;
151155
LastUpgradeCheck = 0700;
152156
ORGANIZATIONNAME = "Xingruo Liu";
153157
TargetAttributes = {
@@ -198,6 +202,7 @@
198202
D1BE3A1319A7D263004BD3F5 /* DLAppDelegate.m in Sources */,
199203
D1BE3A3919AB7000004BD3F5 /* DLDemoViewController.m in Sources */,
200204
D1BE3A0F19A7D263004BD3F5 /* main.m in Sources */,
205+
63B8757B1CBAB95800AE8E98 /* DemoViewController.swift in Sources */,
201206
);
202207
runOnlyForDeploymentPostprocessing = 0;
203208
};
@@ -292,6 +297,7 @@
292297
isa = XCBuildConfiguration;
293298
buildSettings = {
294299
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
300+
CLANG_ENABLE_MODULES = YES;
295301
CLANG_ENABLE_OBJC_ARC = YES;
296302
CODE_SIGN_IDENTITY = "iPhone Developer";
297303
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -307,6 +313,7 @@
307313
PRODUCT_BUNDLE_IDENTIFIER = "com.liuxingruo.$(PRODUCT_NAME)";
308314
PRODUCT_NAME = "$(TARGET_NAME)";
309315
PROVISIONING_PROFILE = "";
316+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
310317
WRAPPER_EXTENSION = app;
311318
};
312319
name = Debug;
@@ -315,6 +322,7 @@
315322
isa = XCBuildConfiguration;
316323
buildSettings = {
317324
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
325+
CLANG_ENABLE_MODULES = YES;
318326
CLANG_ENABLE_OBJC_ARC = YES;
319327
CODE_SIGN_IDENTITY = "iPhone Developer";
320328
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";

Example/DLRadioButtonExample/DLDemoViewController.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@
33

44
@interface DLDemoViewController : UIViewController
55

6-
@property (weak, nonatomic) IBOutlet DLRadioButton *waterButton;
7-
86
@end
Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
#import "DLDemoViewController.h"
22

3-
@implementation DLDemoViewController
3+
@interface DLDemoViewController ()
44

5-
#pragma mark - Helpers
5+
@property (weak, nonatomic) IBOutlet DLRadioButton *waterButton;
66

7-
- (IBAction)logSelectedButton:(DLRadioButton *)radiobutton {
8-
if (radiobutton.isMultipleSelectionEnabled) {
9-
for (DLRadioButton *button in radiobutton.selectedButtons) {
10-
NSLog(@"%@ is selected.\n", button.titleLabel.text);
11-
}
12-
} else {
13-
NSLog(@"%@ is selected.\n", radiobutton.selectedButton.titleLabel.text);
14-
}
15-
}
7+
@end
8+
9+
@implementation DLDemoViewController
1610

1711
#pragma mark - UIViewController
1812

@@ -22,52 +16,63 @@ - (void)viewDidLoad {
2216
// enable multiple selection for water, beer and wine buttons.
2317
self.waterButton.multipleSelectionEnabled = YES;
2418

25-
// programmatically add buttons
19+
// programmatically add button
2620
// first button
27-
DLRadioButton *firstRadioButton = [[DLRadioButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 2 - 131, 350, 262, 17)];
28-
firstRadioButton.titleLabel.font = [UIFont systemFontOfSize:14];
29-
[firstRadioButton setTitle:@"Red Button" forState:UIControlStateNormal];
30-
[firstRadioButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
31-
firstRadioButton.iconColor = [UIColor redColor];
32-
firstRadioButton.indicatorColor = [UIColor redColor];
33-
firstRadioButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
34-
[firstRadioButton addTarget:self action:@selector(logSelectedButton:) forControlEvents:UIControlEventTouchUpInside];
35-
[self.view addSubview:firstRadioButton];
21+
CGRect frame = CGRectMake(self.view.frame.size.width / 2 - 131, 350, 262, 17);
22+
DLRadioButton *firstRadioButton = [self createRadioButtonWithFrame:frame
23+
Title:@"Red Button"
24+
Color:[UIColor redColor]];
3625

3726
// other buttons
3827
NSArray *colorNames = @[@"Brown", @"Orange", @"Green", @"Blue", @"Purple"];
39-
NSArray *buttonColors = @[[UIColor brownColor], [UIColor orangeColor], [UIColor greenColor], [UIColor blueColor], [UIColor purpleColor]];
28+
NSArray *colors = @[[UIColor brownColor], [UIColor orangeColor], [UIColor greenColor], [UIColor blueColor], [UIColor purpleColor]];
4029
NSInteger i = 0;
4130
NSMutableArray *otherButtons = [NSMutableArray new];
42-
for (UIColor *buttonColor in buttonColors) {
43-
// customize button
44-
DLRadioButton *radioButton = [[DLRadioButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 2 - 131, 380 + 30 * i, 262, 17)];
45-
radioButton.titleLabel.font = [UIFont systemFontOfSize:14];
46-
[radioButton setTitle:[colorNames[i] stringByAppendingString:@" Button"] forState:UIControlStateNormal];
47-
[radioButton setTitleColor:buttonColor forState:UIControlStateNormal];
48-
radioButton.iconColor = buttonColor;
49-
radioButton.indicatorColor = buttonColor;
31+
for (UIColor *color in colors) {
32+
CGRect frame = CGRectMake(self.view.frame.size.width / 2 - 131, 380 + 30 * i, 262, 17);
33+
DLRadioButton *radioButton = [self createRadioButtonWithFrame:frame
34+
Title:[colorNames[i] stringByAppendingString:@" Button"]
35+
Color:color];
5036
if (i % 2 == 0) {
5137
radioButton.iconSquare = YES;
5238
}
5339
if (i > 1) {
5440
// put icon on the right side
5541
radioButton.iconOnRight = YES;
5642
radioButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
57-
} else {
58-
radioButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
5943
}
6044
[otherButtons addObject:radioButton];
61-
[radioButton addTarget:self action:@selector(logSelectedButton:) forControlEvents:UIControlEventTouchUpInside];
62-
[self.view addSubview:radioButton];
6345
i++;
6446
}
6547

6648
firstRadioButton.otherButtons = otherButtons;
6749
}
6850

69-
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
51+
#pragma mark - Helper
52+
53+
- (DLRadioButton *)createRadioButtonWithFrame:(CGRect) frame Title:(NSString *)title Color:(UIColor *)color
54+
{
55+
DLRadioButton *radioButton = [[DLRadioButton alloc] initWithFrame:frame];
56+
radioButton.titleLabel.font = [UIFont systemFontOfSize:14];
57+
[radioButton setTitle:title forState:UIControlStateNormal];
58+
[radioButton setTitleColor:color forState:UIControlStateNormal];
59+
radioButton.iconColor = color;
60+
radioButton.indicatorColor = color;
61+
radioButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
62+
[radioButton addTarget:self action:@selector(logSelectedButton:) forControlEvents:UIControlEventTouchUpInside];
63+
[self.view addSubview:radioButton];
7064

65+
return radioButton;
66+
}
67+
68+
- (IBAction)logSelectedButton:(DLRadioButton *)radioButton {
69+
if (radioButton.isMultipleSelectionEnabled) {
70+
for (DLRadioButton *button in radioButton.selectedButtons) {
71+
NSLog(@"%@ is selected.\n", button.titleLabel.text);
72+
}
73+
} else {
74+
NSLog(@"%@ is selected.\n", radioButton.selectedButton.titleLabel.text);
75+
}
7176
}
7277

7378
@end

0 commit comments

Comments
 (0)