Skip to content

Commit

Permalink
Added example for using with Swift.
Browse files Browse the repository at this point in the history
Made APIs more Swift friendly.
  • Loading branch information
DavydLiu committed Apr 10, 2016
1 parent 50216aa commit ffb3ad5
Show file tree
Hide file tree
Showing 13 changed files with 510 additions and 98 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.

---

## [1.4.8](https://github.com/DavydLiu/DLRadioButton/releases/tag/1.4.8) (04/10/2016)
* Added example for using with Swift.
* Made APIs more Swift friendly.


## [1.4.7](https://github.com/DavydLiu/DLRadioButton/releases/tag/1.4.7) (04/02/2016)
* Added support for RTL interface layout.
* Updated API comments.
Expand Down
4 changes: 2 additions & 2 deletions DLRadioButton.podspec.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "DLRadioButton",
"version": "1.4.7",
"version": "1.4.8",
"summary": "A highly customizable Radio Button for iOS",
"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",
"homepage": "https://github.com/DavydLiu/DLRadioButton",
Expand All @@ -17,7 +17,7 @@
},
"source": {
"git": "https://github.com/DavydLiu/DLRadioButton.git",
"tag": "1.4.7"
"tag": "1.4.8"
},
"source_files": "DLRadioButton/**/*.{h,m}",
"exclude_files": "Classes/Exclude",
Expand Down
4 changes: 2 additions & 2 deletions DLRadioButton.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -342,7 +342,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
46 changes: 26 additions & 20 deletions DLRadioButton/DLRadioButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,35 @@
IB_DESIGNABLE
@interface DLRadioButton : UIButton

#pragma mark - Access buttons

/**
* Finds out selected button in same group.
*
* @return Selected button.
*/
- (nullable DLRadioButton *)selectedButton;

/**
* Finds out selected buttons in same group, use it only if multiple selection is enabled.
*
* @return Selected buttons.
*/
- (nonnull NSArray<DLRadioButton *> *)selectedButtons;

/**
* Container for holding other buttons in same group.
*/
@property (nonatomic) IBOutletCollection(DLRadioButton) NSArray *otherButtons;
@property (nonnull, nonatomic) IBOutletCollection(DLRadioButton) NSArray<DLRadioButton *> *otherButtons;

/**
* Clears selection for other buttons in in same group.
*/
- (void)deselectOtherButtons;

#pragma mark - Customization

NS_ASSUME_NONNULL_BEGIN
/**
* Size of icon, default is kDefaulIconSize.
*/
Expand Down Expand Up @@ -66,24 +90,6 @@ IB_DESIGNABLE
* Whether enable multiple selection, default is NO.
*/
@property (nonatomic, getter = isMultipleSelectionEnabled) BOOL multipleSelectionEnabled;

/**
* Finds out selected button in same group.
*
* @return Selected button.
*/
- (DLRadioButton *)selectedButton;

/**
* Finds out selected buttons in same group, use it only if multiple selection is enabled.
*
* @return Selected buttons.
*/
- (NSArray *)selectedButtons;

/**
* Clears selection for other buttons in in same group.
*/
- (void)deselectOtherButtons;
NS_ASSUME_NONNULL_END

@end
Binary file modified Example/DLRadioButton.framework/DLRadioButton
Binary file not shown.
46 changes: 26 additions & 20 deletions Example/DLRadioButton.framework/Headers/DLRadioButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,35 @@
IB_DESIGNABLE
@interface DLRadioButton : UIButton

#pragma mark - Access buttons

/**
* Finds out selected button in same group.
*
* @return Selected button.
*/
- (nullable DLRadioButton *)selectedButton;

/**
* Finds out selected buttons in same group, use it only if multiple selection is enabled.
*
* @return Selected buttons.
*/
- (nonnull NSArray<DLRadioButton *> *)selectedButtons;

/**
* Container for holding other buttons in same group.
*/
@property (nonatomic) IBOutletCollection(DLRadioButton) NSArray *otherButtons;
@property (nonnull, nonatomic) IBOutletCollection(DLRadioButton) NSArray<DLRadioButton *> *otherButtons;

/**
* Clears selection for other buttons in in same group.
*/
- (void)deselectOtherButtons;

#pragma mark - Customization

NS_ASSUME_NONNULL_BEGIN
/**
* Size of icon, default is kDefaulIconSize.
*/
Expand Down Expand Up @@ -66,24 +90,6 @@ IB_DESIGNABLE
* Whether enable multiple selection, default is NO.
*/
@property (nonatomic, getter = isMultipleSelectionEnabled) BOOL multipleSelectionEnabled;

/**
* Finds out selected button in same group.
*
* @return Selected button.
*/
- (DLRadioButton *)selectedButton;

/**
* Finds out selected buttons in same group, use it only if multiple selection is enabled.
*
* @return Selected buttons.
*/
- (NSArray *)selectedButtons;

/**
* Clears selection for other buttons in in same group.
*/
- (void)deselectOtherButtons;
NS_ASSUME_NONNULL_END

@end
4 changes: 2 additions & 2 deletions Example/DLRadioButton.framework/_CodeSignature/CodeResources
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<dict>
<key>Headers/DLRadioButton.h</key>
<data>
AUTpUW+3DpeB/74Awfr3kVxsj5U=
AxrEoeOQUM+yJB38xuZlF8jcNuw=
</data>
<key>Info.plist</key>
<data>
Expand All @@ -21,7 +21,7 @@
<dict>
<key>Headers/DLRadioButton.h</key>
<data>
AUTpUW+3DpeB/74Awfr3kVxsj5U=
AxrEoeOQUM+yJB38xuZlF8jcNuw=
</data>
<key>Modules/module.modulemap</key>
<data>
Expand Down
10 changes: 9 additions & 1 deletion Example/DLRadioButtonExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
63B875781CB047AB00AE8E98 /* DLRadioButton.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 63B875771CB047AB00AE8E98 /* DLRadioButton.framework */; };
63B875791CB0481900AE8E98 /* DLRadioButton.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 63B875771CB047AB00AE8E98 /* DLRadioButton.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
63B8757B1CBAB95800AE8E98 /* DemoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63B8757A1CBAB95800AE8E98 /* DemoViewController.swift */; };
63C933161B48EB1C009DD715 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 63C933151B48EB1C009DD715 /* Images.xcassets */; };
D1BE3A0319A7D263004BD3F5 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D1BE3A0219A7D263004BD3F5 /* Foundation.framework */; };
D1BE3A0519A7D263004BD3F5 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D1BE3A0419A7D263004BD3F5 /* CoreGraphics.framework */; };
Expand Down Expand Up @@ -36,6 +37,7 @@

/* Begin PBXFileReference section */
63B875771CB047AB00AE8E98 /* DLRadioButton.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = DLRadioButton.framework; sourceTree = "<group>"; };
63B8757A1CBAB95800AE8E98 /* DemoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DemoViewController.swift; sourceTree = "<group>"; };
63C933151B48EB1C009DD715 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
D1BE39FF19A7D263004BD3F5 /* DLRadioButtonExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DLRadioButtonExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
D1BE3A0219A7D263004BD3F5 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -101,10 +103,11 @@
D1BE3A1119A7D263004BD3F5 /* DLAppDelegate.h */,
D1BE3A1219A7D263004BD3F5 /* DLAppDelegate.m */,
63C933151B48EB1C009DD715 /* Images.xcassets */,
D1BE3A0919A7D263004BD3F5 /* Supporting Files */,
D1BE3A3519AB683D004BD3F5 /* Main.storyboard */,
D1BE3A3719AB7000004BD3F5 /* DLDemoViewController.h */,
D1BE3A3819AB7000004BD3F5 /* DLDemoViewController.m */,
63B8757A1CBAB95800AE8E98 /* DemoViewController.swift */,
D1BE3A0919A7D263004BD3F5 /* Supporting Files */,
);
path = DLRadioButtonExample;
sourceTree = "<group>";
Expand Down Expand Up @@ -148,6 +151,7 @@
isa = PBXProject;
attributes = {
CLASSPREFIX = DL;
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0700;
ORGANIZATIONNAME = "Xingruo Liu";
TargetAttributes = {
Expand Down Expand Up @@ -198,6 +202,7 @@
D1BE3A1319A7D263004BD3F5 /* DLAppDelegate.m in Sources */,
D1BE3A3919AB7000004BD3F5 /* DLDemoViewController.m in Sources */,
D1BE3A0F19A7D263004BD3F5 /* main.m in Sources */,
63B8757B1CBAB95800AE8E98 /* DemoViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -292,6 +297,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -307,6 +313,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.liuxingruo.$(PRODUCT_NAME)";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
WRAPPER_EXTENSION = app;
};
name = Debug;
Expand All @@ -315,6 +322,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down
2 changes: 0 additions & 2 deletions Example/DLRadioButtonExample/DLDemoViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@

@interface DLDemoViewController : UIViewController

@property (weak, nonatomic) IBOutlet DLRadioButton *waterButton;

@end
75 changes: 40 additions & 35 deletions Example/DLRadioButtonExample/DLDemoViewController.m
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
#import "DLDemoViewController.h"

@implementation DLDemoViewController
@interface DLDemoViewController ()

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

- (IBAction)logSelectedButton:(DLRadioButton *)radiobutton {
if (radiobutton.isMultipleSelectionEnabled) {
for (DLRadioButton *button in radiobutton.selectedButtons) {
NSLog(@"%@ is selected.\n", button.titleLabel.text);
}
} else {
NSLog(@"%@ is selected.\n", radiobutton.selectedButton.titleLabel.text);
}
}
@end

@implementation DLDemoViewController

#pragma mark - UIViewController

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

// programmatically add buttons
// programmatically add button
// first button
DLRadioButton *firstRadioButton = [[DLRadioButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 2 - 131, 350, 262, 17)];
firstRadioButton.titleLabel.font = [UIFont systemFontOfSize:14];
[firstRadioButton setTitle:@"Red Button" forState:UIControlStateNormal];
[firstRadioButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
firstRadioButton.iconColor = [UIColor redColor];
firstRadioButton.indicatorColor = [UIColor redColor];
firstRadioButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[firstRadioButton addTarget:self action:@selector(logSelectedButton:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:firstRadioButton];
CGRect frame = CGRectMake(self.view.frame.size.width / 2 - 131, 350, 262, 17);
DLRadioButton *firstRadioButton = [self createRadioButtonWithFrame:frame
Title:@"Red Button"
Color:[UIColor redColor]];

// other buttons
NSArray *colorNames = @[@"Brown", @"Orange", @"Green", @"Blue", @"Purple"];
NSArray *buttonColors = @[[UIColor brownColor], [UIColor orangeColor], [UIColor greenColor], [UIColor blueColor], [UIColor purpleColor]];
NSArray *colors = @[[UIColor brownColor], [UIColor orangeColor], [UIColor greenColor], [UIColor blueColor], [UIColor purpleColor]];
NSInteger i = 0;
NSMutableArray *otherButtons = [NSMutableArray new];
for (UIColor *buttonColor in buttonColors) {
// customize button
DLRadioButton *radioButton = [[DLRadioButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 2 - 131, 380 + 30 * i, 262, 17)];
radioButton.titleLabel.font = [UIFont systemFontOfSize:14];
[radioButton setTitle:[colorNames[i] stringByAppendingString:@" Button"] forState:UIControlStateNormal];
[radioButton setTitleColor:buttonColor forState:UIControlStateNormal];
radioButton.iconColor = buttonColor;
radioButton.indicatorColor = buttonColor;
for (UIColor *color in colors) {
CGRect frame = CGRectMake(self.view.frame.size.width / 2 - 131, 380 + 30 * i, 262, 17);
DLRadioButton *radioButton = [self createRadioButtonWithFrame:frame
Title:[colorNames[i] stringByAppendingString:@" Button"]
Color:color];
if (i % 2 == 0) {
radioButton.iconSquare = YES;
}
if (i > 1) {
// put icon on the right side
radioButton.iconOnRight = YES;
radioButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
} else {
radioButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
}
[otherButtons addObject:radioButton];
[radioButton addTarget:self action:@selector(logSelectedButton:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:radioButton];
i++;
}

firstRadioButton.otherButtons = otherButtons;
}

- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
#pragma mark - Helper

- (DLRadioButton *)createRadioButtonWithFrame:(CGRect) frame Title:(NSString *)title Color:(UIColor *)color
{
DLRadioButton *radioButton = [[DLRadioButton alloc] initWithFrame:frame];
radioButton.titleLabel.font = [UIFont systemFontOfSize:14];
[radioButton setTitle:title forState:UIControlStateNormal];
[radioButton setTitleColor:color forState:UIControlStateNormal];
radioButton.iconColor = color;
radioButton.indicatorColor = color;
radioButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[radioButton addTarget:self action:@selector(logSelectedButton:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:radioButton];

return radioButton;
}

- (IBAction)logSelectedButton:(DLRadioButton *)radioButton {
if (radioButton.isMultipleSelectionEnabled) {
for (DLRadioButton *button in radioButton.selectedButtons) {
NSLog(@"%@ is selected.\n", button.titleLabel.text);
}
} else {
NSLog(@"%@ is selected.\n", radioButton.selectedButton.titleLabel.text);
}
}

@end
Loading

0 comments on commit ffb3ad5

Please sign in to comment.