From 17aacd14137206ec4692d11ef2a0660a7458fcac Mon Sep 17 00:00:00 2001 From: olunx Date: Mon, 9 Feb 2015 12:43:14 +0800 Subject: [PATCH 1/3] Add auto new row for items. --- .../TNRadioButtonGroupDemo/MainView.m | 16 ++++++++++++-- src/TNRadioButtonGroup.h | 1 + src/TNRadioButtonGroup.m | 22 ++++++++++++++----- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/MainView.m b/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/MainView.m index 40c7f98..7c1daad 100644 --- a/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/MainView.m +++ b/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/MainView.m @@ -51,11 +51,23 @@ - (void)createHorizontalList { alienData.circleColor = [UIColor blackColor]; alienData.borderRadius = 12; alienData.circleRadius = 5; + + TNCircularRadioButtonData *noData = [TNCircularRadioButtonData new]; + noData.labelText = @"noData"; + noData.identifier = @"noData"; + noData.selected = NO; + noData.borderColor = [UIColor blackColor]; + noData.circleColor = [UIColor blackColor]; + noData.borderRadius = 12; + noData.circleRadius = 5; - self.sexGroup = [[TNRadioButtonGroup alloc] initWithRadioButtonData:@[maleData, femaleData, alienData] layout:TNRadioButtonGroupLayoutHorizontal]; + self.sexGroup = [[TNRadioButtonGroup alloc] initWithRadioButtonData:@[maleData, femaleData, alienData, noData] layout:TNRadioButtonGroupLayoutHorizontal]; self.sexGroup.identifier = @"Sex group"; + self.sexGroup.marginBetweenItems = 15; + self.sexGroup.itemsInsets = UIEdgeInsetsMake(15, 15, 0, 0); + self.sexGroup.rowItemCount = 2; [self.sexGroup create]; - self.sexGroup.position = CGPointMake(25, 175); + self.sexGroup.position = CGPointMake(0, 145); [self addSubview:self.sexGroup]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sexGroupUpdated:) name:SELECTED_RADIO_BUTTON_CHANGED object:self.sexGroup]; diff --git a/src/TNRadioButtonGroup.h b/src/TNRadioButtonGroup.h index 99746a7..7138d2a 100755 --- a/src/TNRadioButtonGroup.h +++ b/src/TNRadioButtonGroup.h @@ -24,6 +24,7 @@ typedef enum : NSUInteger { @property (nonatomic) CGPoint position; @property (nonatomic) NSInteger marginBetweenItems; @property (nonatomic) UIEdgeInsets itemsInsets; +@property (nonatomic) NSInteger rowItemCount; @property (nonatomic, strong) UIFont *labelFont; @property (nonatomic, strong) UIColor *labelColor; diff --git a/src/TNRadioButtonGroup.m b/src/TNRadioButtonGroup.m index 4fd56e3..dd473e7 100755 --- a/src/TNRadioButtonGroup.m +++ b/src/TNRadioButtonGroup.m @@ -31,6 +31,7 @@ - (instancetype)initWithRadioButtonData:(NSArray *)radioButtonData layout:(TNRad self.layout = layout; self.marginBetweenItems = 15; self.itemsInsets = UIEdgeInsetsZero; + self.rowItemCount = 3; } return self; @@ -53,9 +54,10 @@ - (void)createRadioButtons { int xPos = _itemsInsets.left; int yPos = _itemsInsets.top; + int maxWidth = 0; int maxHeight = 0; int i = 0; - + NSMutableArray *tmp = [NSMutableArray new]; for (TNRadioButtonData *data in self.radioButtonData) { @@ -83,20 +85,28 @@ - (void)createRadioButtons { radioButton.delegate = self; CGRect frame; - + int rows = (i + self.rowItemCount) / self.rowItemCount; if( self.layout == TNRadioButtonGroupLayoutHorizontal ){ - frame = CGRectMake(xPos, _itemsInsets.top, radioButton.frame.size.width, radioButton.frame.size.height); + if(i % self.rowItemCount == 0){ + xPos = _itemsInsets.left; + }else{ + yPos -= radioButton.frame.size.height + self.marginBetweenItems; + } + frame = CGRectMake(xPos, yPos, radioButton.frame.size.width, radioButton.frame.size.height); + maxWidth = self.rowItemCount * (radioButton.frame.size.width + self.marginBetweenItems); + maxHeight = rows * (radioButton.frame.size.height + self.marginBetweenItems) + self.marginBetweenItems; }else{ frame = CGRectMake(_itemsInsets.left, yPos, radioButton.frame.size.width, radioButton.frame.size.height); } radioButton.frame = frame; [self addSubview:radioButton]; - + xPos += radioButton.frame.size.width + self.marginBetweenItems; yPos += radioButton.frame.size.height + self.marginBetweenItems; + maxWidth = MAX(maxWidth, radioButton.frame.size.width); maxHeight = MAX(maxHeight, radioButton.frame.size.height); - + if( self.layout == TNRadioButtonGroupLayoutVertical ){ maxHeight = yPos; } @@ -109,7 +119,7 @@ - (void)createRadioButtons { i++; } - self.widthOfComponent = xPos; + self.widthOfComponent = maxWidth; self.heightOfComponent = maxHeight; self.radioButtons = [NSArray arrayWithArray:tmp]; } From ee6523f78cb2bb432c7fbf5d9547879180b5dda4 Mon Sep 17 00:00:00 2001 From: olunx Date: Tue, 10 Feb 2015 11:33:29 +0800 Subject: [PATCH 2/3] Add fill type radio button.Change label type from UILabel to UIButton for more features. --- .../project.pbxproj | 28 +++++++++++ .../TNRadioButtonGroupDemo/MainView.h | 1 + .../TNRadioButtonGroupDemo/MainView.m | 41 +++++++++++++++ src/TNFillRadioButton.h | 17 +++++++ src/TNFillRadioButton.m | 50 +++++++++++++++++++ src/TNFillRadioButtonData.h | 18 +++++++ src/TNFillRadioButtonData.m | 13 +++++ src/TNRadioButton.h | 3 +- src/TNRadioButton.m | 27 ++++++---- src/TNRadioButtonData.h | 10 +++- src/TNRadioButtonData.m | 15 +++++- src/TNRadioButtonGroup.h | 1 + src/TNRadioButtonGroup.m | 6 ++- 13 files changed, 213 insertions(+), 17 deletions(-) create mode 100644 src/TNFillRadioButton.h create mode 100644 src/TNFillRadioButton.m create mode 100644 src/TNFillRadioButtonData.h create mode 100644 src/TNFillRadioButtonData.m diff --git a/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo.xcodeproj/project.pbxproj b/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo.xcodeproj/project.pbxproj index feabf58..a2d78f3 100644 --- a/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo.xcodeproj/project.pbxproj +++ b/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo.xcodeproj/project.pbxproj @@ -30,6 +30,8 @@ 86CEDBA31907046D004B016A /* TNRectangularRadioButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 86CEDBA21907046D004B016A /* TNRectangularRadioButton.m */; }; 86CEDBA619070476004B016A /* TNImageRadioButtonData.m in Sources */ = {isa = PBXBuildFile; fileRef = 86CEDBA519070476004B016A /* TNImageRadioButtonData.m */; }; 86CEDBA919070483004B016A /* TNImageRadioButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 86CEDBA819070483004B016A /* TNImageRadioButton.m */; }; + C8EE178D1A88B356001A1587 /* TNFillRadioButtonData.m in Sources */ = {isa = PBXBuildFile; fileRef = C8EE178C1A88B356001A1587 /* TNFillRadioButtonData.m */; }; + C8EE17901A88B3B4001A1587 /* TNFillRadioButton.m in Sources */ = {isa = PBXBuildFile; fileRef = C8EE178F1A88B3B4001A1587 /* TNFillRadioButton.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -83,6 +85,10 @@ 86CEDBA519070476004B016A /* TNImageRadioButtonData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TNImageRadioButtonData.m; path = ../../src/TNImageRadioButtonData.m; sourceTree = ""; }; 86CEDBA719070483004B016A /* TNImageRadioButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TNImageRadioButton.h; path = ../../src/TNImageRadioButton.h; sourceTree = ""; }; 86CEDBA819070483004B016A /* TNImageRadioButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TNImageRadioButton.m; path = ../../src/TNImageRadioButton.m; sourceTree = ""; }; + C8EE178B1A88B356001A1587 /* TNFillRadioButtonData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TNFillRadioButtonData.h; path = ../../src/TNFillRadioButtonData.h; sourceTree = ""; }; + C8EE178C1A88B356001A1587 /* TNFillRadioButtonData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TNFillRadioButtonData.m; path = ../../src/TNFillRadioButtonData.m; sourceTree = ""; }; + C8EE178E1A88B3B4001A1587 /* TNFillRadioButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TNFillRadioButton.h; path = ../../src/TNFillRadioButton.h; sourceTree = ""; }; + C8EE178F1A88B3B4001A1587 /* TNFillRadioButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TNFillRadioButton.m; path = ../../src/TNFillRadioButton.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -204,6 +210,7 @@ 86CEDB6D1906B211004B016A /* Types */ = { isa = PBXGroup; children = ( + C8EE17891A88B2E2001A1587 /* Fill */, 86CEDB6F1906B22E004B016A /* Base */, 86CEDB6E1906B229004B016A /* Circular */, 86CEDB8D1906FDF5004B016A /* Rectangle */, @@ -299,6 +306,25 @@ name = Data; sourceTree = ""; }; + C8EE17891A88B2E2001A1587 /* Fill */ = { + isa = PBXGroup; + children = ( + C8EE178A1A88B2F8001A1587 /* Data */, + C8EE178E1A88B3B4001A1587 /* TNFillRadioButton.h */, + C8EE178F1A88B3B4001A1587 /* TNFillRadioButton.m */, + ); + name = Fill; + sourceTree = ""; + }; + C8EE178A1A88B2F8001A1587 /* Data */ = { + isa = PBXGroup; + children = ( + C8EE178B1A88B356001A1587 /* TNFillRadioButtonData.h */, + C8EE178C1A88B356001A1587 /* TNFillRadioButtonData.m */, + ); + name = Data; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -394,10 +420,12 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + C8EE178D1A88B356001A1587 /* TNFillRadioButtonData.m in Sources */, 86465FE41906ABD200E7FDE9 /* AppDelegate.m in Sources */, 86CEDBA019070464004B016A /* TNRectangularRadioButtonData.m in Sources */, 86CEDB8C1906FDEA004B016A /* TNCircularRadioButtonData.m in Sources */, 86CEDB891906FDE1004B016A /* TNRadioButtonData.m in Sources */, + C8EE17901A88B3B4001A1587 /* TNFillRadioButton.m in Sources */, 86465FE01906ABD200E7FDE9 /* main.m in Sources */, 86CEDB721906B4F9004B016A /* MainViewController.m in Sources */, 86CEDBA31907046D004B016A /* TNRectangularRadioButton.m in Sources */, diff --git a/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/MainView.h b/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/MainView.h index 8cc026e..71aafc3 100644 --- a/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/MainView.h +++ b/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/MainView.h @@ -16,5 +16,6 @@ @property (nonatomic, strong) TNRadioButtonGroup *sexGroup; @property (nonatomic, strong) TNRadioButtonGroup *hobbiesGroup; @property (nonatomic, strong) TNRadioButtonGroup *temperatureGroup; +@property (nonatomic, strong) TNRadioButtonGroup *noGroup; @end diff --git a/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/MainView.m b/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/MainView.m index 7c1daad..8007b5d 100644 --- a/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/MainView.m +++ b/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/MainView.m @@ -22,6 +22,7 @@ - (id)initWithFrame:(CGRect)frame { [self createHorizontalList]; [self createVerticalList]; [self createHorizontalListWithImage]; + [self createHorizontalListWithBg]; } return self; @@ -149,6 +150,41 @@ - (void)createHorizontalListWithImage { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(temperatureGroupUpdated:) name:SELECTED_RADIO_BUTTON_CHANGED object:self.temperatureGroup]; } +- (void)createHorizontalListWithBg { + TNFillRadioButtonData *firstData = [TNFillRadioButtonData new]; + firstData.labelText = @"First"; + firstData.identifier = @"First"; + firstData.selected = NO; + firstData.labelBgNormalColor = [UIColor grayColor]; + firstData.labelBgSelectedColor = [UIColor redColor]; + firstData.labelMarginLeft = -1; + firstData.labelWidth = 60.0f; + firstData.labelHeight = 30.0f; + firstData.labelBorderWidth = 1.0; + firstData.labelBorderColor = [UIColor brownColor].CGColor; + firstData.labelBorderCornerRadius = 5.0; + + TNFillRadioButtonData *secondData = [TNFillRadioButtonData new]; + secondData.labelText = @"Second"; + secondData.identifier = @"Second"; + secondData.selected = NO; + secondData.labelBgNormalColor = [UIColor grayColor]; + secondData.labelBgSelectedColor = [UIColor redColor]; + secondData.labelMarginLeft = -1; + secondData.labelWidth = 60.0f; + secondData.labelHeight = 30.0f; + + + self.noGroup = [[TNRadioButtonGroup alloc] initWithRadioButtonData:@[firstData, secondData] layout:TNRadioButtonGroupLayoutHorizontal]; + self.noGroup.identifier = @"No Group"; + [self.noGroup create]; + self.noGroup.position = CGPointMake(0, 500); + + [self addSubview:self.noGroup]; + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(noGroupUpdated:) name:SELECTED_RADIO_BUTTON_CHANGED object:self.noGroup]; +} + - (void)sexGroupUpdated:(NSNotification *)notification { NSLog(@"[MainView] Sex group updated to %@", self.sexGroup.selectedRadioButton.data.identifier); } @@ -161,10 +197,15 @@ - (void)temperatureGroupUpdated:(NSNotification *)notification { NSLog(@"[MainView] Temperature group updated to %@", self.temperatureGroup.selectedRadioButton.data.identifier); } +- (void)noGroupUpdated:(NSNotification *)notification { + NSLog(@"[MainView] No. group updated to %@", self.noGroup.selectedRadioButton.data.identifier); +} + - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self name:SELECTED_RADIO_BUTTON_CHANGED object:self.sexGroup]; [[NSNotificationCenter defaultCenter] removeObserver:self name:SELECTED_RADIO_BUTTON_CHANGED object:self.hobbiesGroup]; [[NSNotificationCenter defaultCenter] removeObserver:self name:SELECTED_RADIO_BUTTON_CHANGED object:self.temperatureGroup]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:SELECTED_RADIO_BUTTON_CHANGED object:self.noGroup]; } @end diff --git a/src/TNFillRadioButton.h b/src/TNFillRadioButton.h new file mode 100644 index 0000000..7f945b3 --- /dev/null +++ b/src/TNFillRadioButton.h @@ -0,0 +1,17 @@ +// +// TNFillRadioButton.h +// TNRadioButtonGroupDemo +// +// Created by olunx on 15/2/9. +// Copyright (c) 2015年 Frederik Jacques. All rights reserved. +// + +#import "TNRadioButton.h" + +@interface TNFillRadioButton : TNRadioButton + +@property (nonatomic, strong) TNFillRadioButtonData *data; + +- (instancetype)initWithData:(TNFillRadioButtonData *)data; + +@end diff --git a/src/TNFillRadioButton.m b/src/TNFillRadioButton.m new file mode 100644 index 0000000..d21cfba --- /dev/null +++ b/src/TNFillRadioButton.m @@ -0,0 +1,50 @@ +// +// TNFillRadioButton.m +// TNRadioButtonGroupDemo +// +// Created by olunx on 15/2/9. +// Copyright (c) 2015年 Frederik Jacques. All rights reserved. +// + +#import "TNFillRadioButton.h" + +@implementation TNFillRadioButton + +#pragma mark - Initializers + +- (instancetype)initWithData:(TNFillRadioButtonData *)data { + + self = [super initWithData:data]; + + if (self) { + // Initialization code + self.data = data; + + [self setup]; + } + + return self; +} + +#pragma mark - Creation +- (void)setup{ + + [self createRadioButton]; + + [super setup]; +} + +- (void)update { + [super update]; + + self.lblButton.backgroundColor = ( self.data.selected ) ? self.data.labelBgSelectedColor : self.data.labelBgNormalColor; +} + +#pragma mark - Animations +- (void)selectWithAnimation:(BOOL)animated { + + self.lblButton.backgroundColor = ( self.data.selected ) ? self.data.labelBgSelectedColor : self.data.labelBgNormalColor; + +} + +@end diff --git a/src/TNFillRadioButtonData.h b/src/TNFillRadioButtonData.h new file mode 100644 index 0000000..fdeea95 --- /dev/null +++ b/src/TNFillRadioButtonData.h @@ -0,0 +1,18 @@ +// +// TNFillRadioButtonData.h +// TNRadioButtonGroupDemo +// +// Created by olunx on 15/2/9. +// Copyright (c) 2015年 Frederik Jacques. All rights reserved. +// + +#import "TNRadioButtonData.h" + +@interface TNFillRadioButtonData : TNRadioButtonData + +@property (nonatomic, strong) UIColor *labelBorderNormalColor; +@property (nonatomic, strong) UIColor *labelBorderSelectedColor; +@property (nonatomic, strong) UIColor *labelBgNormalColor; +@property (nonatomic, strong) UIColor *labelBgSelectedColor; + +@end diff --git a/src/TNFillRadioButtonData.m b/src/TNFillRadioButtonData.m new file mode 100644 index 0000000..61e2b91 --- /dev/null +++ b/src/TNFillRadioButtonData.m @@ -0,0 +1,13 @@ +// +// TNFillRadioButtonData.m +// TNRadioButtonGroupDemo +// +// Created by olunx on 15/2/9. +// Copyright (c) 2015年 Frederik Jacques. All rights reserved. +// + +#import "TNFillRadioButtonData.h" + +@implementation TNFillRadioButtonData + +@end diff --git a/src/TNRadioButton.h b/src/TNRadioButton.h index 0cb1a24..e01a2d7 100644 --- a/src/TNRadioButton.h +++ b/src/TNRadioButton.h @@ -14,6 +14,7 @@ #import "TNCircularRadioButtonData.h" #import "TNRectangularRadioButtonData.h" #import "TNImageRadioButtonData.h" +#import "TNFillRadioButtonData.h" @interface TNRadioButton : UIView @@ -22,7 +23,7 @@ @property (nonatomic, strong) TNRadioButtonData *data; @property (nonatomic, strong) UIView *radioButton; -@property (nonatomic, strong) UILabel *lblLabel; +@property (nonatomic, strong) UIButton *lblButton; @property (nonatomic, strong) UIButton *btnHidden; @property (nonatomic, weak) id delegate; diff --git a/src/TNRadioButton.m b/src/TNRadioButton.m index 09ba075..ec40d98 100755 --- a/src/TNRadioButton.m +++ b/src/TNRadioButton.m @@ -39,12 +39,17 @@ - (void)update { } - (void)updateLabel { - self.lblLabel.backgroundColor = [UIColor clearColor]; - self.lblLabel.numberOfLines = 0; - self.lblLabel.lineBreakMode = NSLineBreakByWordWrapping; - self.lblLabel.font = self.data.labelFont; - self.lblLabel.textColor = self.data.labelColor; - self.lblLabel.text = self.data.labelText; + self.lblButton.backgroundColor = [UIColor clearColor]; + self.lblButton.titleLabel.font = self.data.labelFont; + [self.lblButton setTitleColor:self.data.labelColor forState:UIControlStateNormal]; + [self.lblButton setTitle:self.data.labelText forState:UIControlStateNormal]; + + if(self.data.labelBorderWidth){ + self.lblButton.layer.masksToBounds = YES; + self.lblButton.layer.cornerRadius = self.data.labelBorderCornerRadius ?: 5.0; + self.lblButton.layer.borderWidth = self.data.labelBorderWidth ?: 1.0; + self.lblButton.layer.borderColor = self.data.labelBorderColor ?: [UIColor grayColor].CGColor; + } } - (void)createRadioButton {} @@ -63,17 +68,17 @@ - (void)createLabel { } - self.lblLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.radioButton.frame.origin.x + self.radioButton.frame.size.width + 15, (self.radioButton.frame.size.height - labelSize.height) / 2, labelSize.width, labelSize.height)]; - [self updateLabel]; - [self addSubview:self.lblLabel]; + self.lblButton = [[UIButton alloc] initWithFrame:CGRectMake(self.radioButton.frame.origin.x + self.radioButton.frame.size.width + self.data.labelMarginLeft, (self.radioButton.frame.size.height - labelSize.height) / 2, self.data.labelWidth ?: labelSize.width, self.data.labelHeight ?: labelSize.height)]; + [self updateLabel]; + [self addSubview:self.lblButton]; } - (void)createHiddenButton { - int height = MAX(self.lblLabel.frame.size.height, self.radioButton.frame.size.height); + int height = MAX(self.lblButton.frame.size.height, self.radioButton.frame.size.height); self.btnHidden = [UIButton buttonWithType:UIButtonTypeCustom]; - self.btnHidden.frame = CGRectMake(0, 0, self.lblLabel.frame.origin.x + self.lblLabel.frame.size.width, height); + self.btnHidden.frame = CGRectMake(0, 0, self.lblButton.frame.origin.x + self.lblButton.frame.size.width, height); [self addSubview:self.btnHidden]; [self.btnHidden addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside]; diff --git a/src/TNRadioButtonData.h b/src/TNRadioButtonData.h index a5845aa..d623b50 100644 --- a/src/TNRadioButtonData.h +++ b/src/TNRadioButtonData.h @@ -12,10 +12,18 @@ @property (nonatomic, copy) NSString *identifier; @property (nonatomic) NSInteger tag; -@property (nonatomic, copy) NSString *labelText; @property (nonatomic) BOOL selected; +@property (nonatomic, copy) NSString *labelText; @property (nonatomic, strong) UIFont *labelFont; @property (nonatomic, strong) UIColor *labelColor; +@property (nonatomic) NSInteger labelMarginLeft; +@property (nonatomic) CGFloat labelWidth; +@property (nonatomic) CGFloat labelHeight; + +@property (nonatomic) CGFloat labelBorderWidth; +@property (nonatomic) CGFloat labelBorderCornerRadius; +@property (nonatomic) CGColorRef labelBorderColor; + @end diff --git a/src/TNRadioButtonData.m b/src/TNRadioButtonData.m index 2394c35..6e3b206 100755 --- a/src/TNRadioButtonData.m +++ b/src/TNRadioButtonData.m @@ -17,12 +17,23 @@ - (NSString *)description { } #pragma mark - Getters and setters +-(NSInteger)labelMarginLeft { + + if (_labelMarginLeft < 0) { + _labelMarginLeft = 0; + }else{ + _labelMarginLeft = 15; + } + + return _labelMarginLeft; +} + -(UIFont *)labelFont { - + if (!_labelFont) { _labelFont = [UIFont systemFontOfSize:14.0f]; } - + return _labelFont; } diff --git a/src/TNRadioButtonGroup.h b/src/TNRadioButtonGroup.h index 7138d2a..4c7d096 100755 --- a/src/TNRadioButtonGroup.h +++ b/src/TNRadioButtonGroup.h @@ -10,6 +10,7 @@ #import "TNCircularRadioButton.h" #import "TNRectangularRadioButton.h" #import "TNImageRadioButton.h" +#import "TNFillRadioButton.h" extern NSString *const SELECTED_RADIO_BUTTON_CHANGED; diff --git a/src/TNRadioButtonGroup.m b/src/TNRadioButtonGroup.m index dd473e7..6ddf92e 100755 --- a/src/TNRadioButtonGroup.m +++ b/src/TNRadioButtonGroup.m @@ -66,13 +66,15 @@ - (void)createRadioButtons { if( !data.labelFont) data.labelFont = self.labelFont; if( !data.labelColor) data.labelColor = self.labelColor; - + if( [data isKindOfClass:[TNCircularRadioButtonData class]] ){ radioButton = [[TNCircularRadioButton alloc] initWithData:(TNCircularRadioButtonData *)data]; }else if( [data isKindOfClass:[TNRectangularRadioButtonData class]] ){ radioButton = [[TNRectangularRadioButton alloc] initWithData:(TNRectangularRadioButtonData *)data]; }else if( [data isKindOfClass:[TNImageRadioButtonData class]] ){ radioButton = [[TNImageRadioButton alloc] initWithData:(TNImageRadioButtonData *)data]; + }else { + radioButton = [[TNFillRadioButton alloc] initWithData:(TNFillRadioButtonData *)data]; } // If there is already a radio button selected ... deselect the current one @@ -85,7 +87,7 @@ - (void)createRadioButtons { radioButton.delegate = self; CGRect frame; - int rows = (i + self.rowItemCount) / self.rowItemCount; + long rows = (i + self.rowItemCount) / self.rowItemCount; if( self.layout == TNRadioButtonGroupLayoutHorizontal ){ if(i % self.rowItemCount == 0){ xPos = _itemsInsets.left; From 13f6a90d2e4ade4f4d883515254476f72c92571e Mon Sep 17 00:00:00 2001 From: olunx Date: Tue, 10 Feb 2015 15:46:58 +0800 Subject: [PATCH 3/3] Change developer target to 7.0. --- .../project.pbxproj | 38 +++++++++---------- .../AppIcon.appiconset/Contents.json | 5 +++ .../background.imageset/Contents.json | 12 ++++++ .../checked.imageset/Contents.json | 4 ++ .../unchecked.imageset/Contents.json | 4 ++ src/TNFillRadioButtonData.h | 2 - src/TNRadioButton.m | 15 ++------ src/TNRadioButtonData.h | 1 + 8 files changed, 48 insertions(+), 33 deletions(-) diff --git a/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo.xcodeproj/project.pbxproj b/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo.xcodeproj/project.pbxproj index a2d78f3..b0377b7 100644 --- a/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo.xcodeproj/project.pbxproj +++ b/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 64F0EA90A3CD2B8AE36CD1CE /* TNRadioButtonData.m in Sources */ = {isa = PBXBuildFile; fileRef = 64F0E9BD6B31F51D01EC5BC3 /* TNRadioButtonData.m */; }; 86465FD41906ABD200E7FDE9 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 86465FD31906ABD200E7FDE9 /* Foundation.framework */; }; 86465FD61906ABD200E7FDE9 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 86465FD51906ABD200E7FDE9 /* CoreGraphics.framework */; }; 86465FD81906ABD200E7FDE9 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 86465FD71906ABD200E7FDE9 /* UIKit.framework */; }; @@ -24,7 +25,6 @@ 86CEDB671906B1F1004B016A /* TNRadioButtonGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = 86CEDB601906B1F1004B016A /* TNRadioButtonGroup.m */; }; 86CEDB721906B4F9004B016A /* MainViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 86CEDB711906B4F9004B016A /* MainViewController.m */; }; 86CEDB761906B50A004B016A /* MainView.m in Sources */ = {isa = PBXBuildFile; fileRef = 86CEDB751906B50A004B016A /* MainView.m */; }; - 86CEDB891906FDE1004B016A /* TNRadioButtonData.m in Sources */ = {isa = PBXBuildFile; fileRef = 86CEDB881906FDE1004B016A /* TNRadioButtonData.m */; }; 86CEDB8C1906FDEA004B016A /* TNCircularRadioButtonData.m in Sources */ = {isa = PBXBuildFile; fileRef = 86CEDB8B1906FDEA004B016A /* TNCircularRadioButtonData.m */; }; 86CEDBA019070464004B016A /* TNRectangularRadioButtonData.m in Sources */ = {isa = PBXBuildFile; fileRef = 86CEDB9F19070464004B016A /* TNRectangularRadioButtonData.m */; }; 86CEDBA31907046D004B016A /* TNRectangularRadioButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 86CEDBA21907046D004B016A /* TNRectangularRadioButton.m */; }; @@ -45,6 +45,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 64F0E706D0BDAF78C7D3ED98 /* TNRadioButtonData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TNRadioButtonData.h; path = ../../src/TNRadioButtonData.h; sourceTree = ""; }; + 64F0E9BD6B31F51D01EC5BC3 /* TNRadioButtonData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TNRadioButtonData.m; path = ../../src/TNRadioButtonData.m; sourceTree = ""; }; 86465FD01906ABD200E7FDE9 /* TNRadioButtonGroupDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TNRadioButtonGroupDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 86465FD31906ABD200E7FDE9 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 86465FD51906ABD200E7FDE9 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; @@ -72,8 +74,6 @@ 86CEDB711906B4F9004B016A /* MainViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MainViewController.m; sourceTree = ""; }; 86CEDB741906B50A004B016A /* MainView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MainView.h; sourceTree = ""; }; 86CEDB751906B50A004B016A /* MainView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MainView.m; sourceTree = ""; }; - 86CEDB871906FDE1004B016A /* TNRadioButtonData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TNRadioButtonData.h; path = ../../src/TNRadioButtonData.h; sourceTree = ""; }; - 86CEDB881906FDE1004B016A /* TNRadioButtonData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TNRadioButtonData.m; path = ../../src/TNRadioButtonData.m; sourceTree = ""; }; 86CEDB8A1906FDEA004B016A /* TNCircularRadioButtonData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TNCircularRadioButtonData.h; path = ../../src/TNCircularRadioButtonData.h; sourceTree = ""; }; 86CEDB8B1906FDEA004B016A /* TNCircularRadioButtonData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TNCircularRadioButtonData.m; path = ../../src/TNCircularRadioButtonData.m; sourceTree = ""; }; 86CEDB9D19070457004B016A /* TNRadioButtonDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TNRadioButtonDelegate.h; path = ../../src/TNRadioButtonDelegate.h; sourceTree = ""; }; @@ -115,6 +115,15 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 64F0E4A8D2D712A5B0CD80B5 /* Data */ = { + isa = PBXGroup; + children = ( + 64F0E706D0BDAF78C7D3ED98 /* TNRadioButtonData.h */, + 64F0E9BD6B31F51D01EC5BC3 /* TNRadioButtonData.m */, + ); + name = Data; + sourceTree = ""; + }; 86465FC71906ABD200E7FDE9 = { isa = PBXGroup; children = ( @@ -193,7 +202,6 @@ 86BA542B1909896300E75362 /* Protocol */, 86CEDB5F1906B1F1004B016A /* TNRadioButtonGroup.h */, 86CEDB601906B1F1004B016A /* TNRadioButtonGroup.m */, - 86CEDB7A1906D972004B016A /* Data */, 86CEDB6D1906B211004B016A /* Types */, ); name = TNRadioButtonGroup; @@ -213,7 +221,7 @@ C8EE17891A88B2E2001A1587 /* Fill */, 86CEDB6F1906B22E004B016A /* Base */, 86CEDB6E1906B229004B016A /* Circular */, - 86CEDB8D1906FDF5004B016A /* Rectangle */, + 86CEDB8D1906FDF5004B016A /* Rectangular */, 86CEDB95190700F5004B016A /* Image */, ); name = Types; @@ -235,6 +243,7 @@ 86CEDB5D1906B1F1004B016A /* TNRadioButton.h */, 86CEDB5E1906B1F1004B016A /* TNRadioButton.m */, 86CEDB9D19070457004B016A /* TNRadioButtonDelegate.h */, + 64F0E4A8D2D712A5B0CD80B5 /* Data */, ); name = Base; sourceTree = ""; @@ -250,15 +259,6 @@ name = "View controllers"; sourceTree = ""; }; - 86CEDB7A1906D972004B016A /* Data */ = { - isa = PBXGroup; - children = ( - 86CEDB871906FDE1004B016A /* TNRadioButtonData.h */, - 86CEDB881906FDE1004B016A /* TNRadioButtonData.m */, - ); - name = Data; - sourceTree = ""; - }; 86CEDB7F1906E5AA004B016A /* Data */ = { isa = PBXGroup; children = ( @@ -268,14 +268,14 @@ name = Data; sourceTree = ""; }; - 86CEDB8D1906FDF5004B016A /* Rectangle */ = { + 86CEDB8D1906FDF5004B016A /* Rectangular */ = { isa = PBXGroup; children = ( 86CEDB8E1906FDFE004B016A /* Data */, 86CEDBA11907046D004B016A /* TNRectangularRadioButton.h */, 86CEDBA21907046D004B016A /* TNRectangularRadioButton.m */, ); - name = Rectangle; + name = Rectangular; sourceTree = ""; }; 86CEDB8E1906FDFE004B016A /* Data */ = { @@ -424,7 +424,6 @@ 86465FE41906ABD200E7FDE9 /* AppDelegate.m in Sources */, 86CEDBA019070464004B016A /* TNRectangularRadioButtonData.m in Sources */, 86CEDB8C1906FDEA004B016A /* TNCircularRadioButtonData.m in Sources */, - 86CEDB891906FDE1004B016A /* TNRadioButtonData.m in Sources */, C8EE17901A88B3B4001A1587 /* TNFillRadioButton.m in Sources */, 86465FE01906ABD200E7FDE9 /* main.m in Sources */, 86CEDB721906B4F9004B016A /* MainViewController.m in Sources */, @@ -435,6 +434,7 @@ 86CEDB651906B1F1004B016A /* TNCircularRadioButton.m in Sources */, 86CEDB661906B1F1004B016A /* TNRadioButton.m in Sources */, 86CEDB671906B1F1004B016A /* TNRadioButtonGroup.m in Sources */, + 64F0EA90A3CD2B8AE36CD1CE /* TNRadioButtonData.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -554,7 +554,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "TNRadioButtonGroupDemo/TNRadioButtonGroupDemo-Prefix.pch"; INFOPLIST_FILE = "TNRadioButtonGroupDemo/TNRadioButtonGroupDemo-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 6.1; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; @@ -568,7 +568,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "TNRadioButtonGroupDemo/TNRadioButtonGroupDemo-Prefix.pch"; INFOPLIST_FILE = "TNRadioButtonGroupDemo/TNRadioButtonGroupDemo-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 6.1; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; diff --git a/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/Images.xcassets/AppIcon.appiconset/Contents.json b/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/Images.xcassets/AppIcon.appiconset/Contents.json index a396706..33ec0bc 100644 --- a/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/Images.xcassets/AppIcon.appiconset/Contents.json @@ -14,6 +14,11 @@ "idiom" : "iphone", "size" : "60x60", "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" } ], "info" : { diff --git a/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/Images.xcassets/background.imageset/Contents.json b/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/Images.xcassets/background.imageset/Contents.json index 503340a..c73fcad 100644 --- a/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/Images.xcassets/background.imageset/Contents.json +++ b/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/Images.xcassets/background.imageset/Contents.json @@ -1,9 +1,17 @@ { "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, { "idiom" : "universal", "scale" : "2x" }, + { + "idiom" : "universal", + "scale" : "3x" + }, { "idiom" : "iphone", "scale" : "1x" @@ -18,6 +26,10 @@ "filename" : "bg-i5@2x.png", "subtype" : "retina4", "scale" : "2x" + }, + { + "idiom" : "iphone", + "scale" : "3x" } ], "info" : { diff --git a/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/Images.xcassets/checked.imageset/Contents.json b/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/Images.xcassets/checked.imageset/Contents.json index 72816df..0f6227e 100644 --- a/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/Images.xcassets/checked.imageset/Contents.json +++ b/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/Images.xcassets/checked.imageset/Contents.json @@ -9,6 +9,10 @@ "idiom" : "universal", "scale" : "2x", "filename" : "checked@2x.png" + }, + { + "idiom" : "universal", + "scale" : "3x" } ], "info" : { diff --git a/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/Images.xcassets/unchecked.imageset/Contents.json b/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/Images.xcassets/unchecked.imageset/Contents.json index 328fc6e..5c3cc69 100644 --- a/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/Images.xcassets/unchecked.imageset/Contents.json +++ b/TNRadioButtonGroupDemo/TNRadioButtonGroupDemo/Images.xcassets/unchecked.imageset/Contents.json @@ -9,6 +9,10 @@ "idiom" : "universal", "scale" : "2x", "filename" : "unchecked@2x.png" + }, + { + "idiom" : "universal", + "scale" : "3x" } ], "info" : { diff --git a/src/TNFillRadioButtonData.h b/src/TNFillRadioButtonData.h index fdeea95..a679dda 100644 --- a/src/TNFillRadioButtonData.h +++ b/src/TNFillRadioButtonData.h @@ -10,8 +10,6 @@ @interface TNFillRadioButtonData : TNRadioButtonData -@property (nonatomic, strong) UIColor *labelBorderNormalColor; -@property (nonatomic, strong) UIColor *labelBorderSelectedColor; @property (nonatomic, strong) UIColor *labelBgNormalColor; @property (nonatomic, strong) UIColor *labelBgSelectedColor; diff --git a/src/TNRadioButton.m b/src/TNRadioButton.m index ec40d98..b83ca61 100755 --- a/src/TNRadioButton.m +++ b/src/TNRadioButton.m @@ -55,18 +55,9 @@ - (void)updateLabel { - (void)createRadioButton {} - (void)createLabel { - - CGSize labelSize; - - if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) { - labelSize = [self.data.labelText sizeWithFont:self.data.labelFont forWidth:150 lineBreakMode:NSLineBreakByWordWrapping]; - - } else { - CGRect labelRect = [self.data.labelText boundingRectWithSize:CGSizeMake(150, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:self.data.labelFont} context:nil]; - - labelSize = CGSizeMake(labelRect.size.width, labelRect.size.height); - - } + + CGRect labelRect = [self.data.labelText boundingRectWithSize:CGSizeMake(150, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:self.data.labelFont} context:nil]; + CGSize labelSize = CGSizeMake(labelRect.size.width, labelRect.size.height); self.lblButton = [[UIButton alloc] initWithFrame:CGRectMake(self.radioButton.frame.origin.x + self.radioButton.frame.size.width + self.data.labelMarginLeft, (self.radioButton.frame.size.height - labelSize.height) / 2, self.data.labelWidth ?: labelSize.width, self.data.labelHeight ?: labelSize.height)]; [self updateLabel]; diff --git a/src/TNRadioButtonData.h b/src/TNRadioButtonData.h index d623b50..bdcaf9c 100644 --- a/src/TNRadioButtonData.h +++ b/src/TNRadioButtonData.h @@ -15,6 +15,7 @@ @property (nonatomic) BOOL selected; @property (nonatomic, copy) NSString *labelText; + @property (nonatomic, strong) UIFont *labelFont; @property (nonatomic, strong) UIColor *labelColor;