From 4d65312ac160c2ec69d0db8e9b35dd830071ba9c Mon Sep 17 00:00:00 2001 From: pierre-yves boulbin Date: Thu, 18 Feb 2016 11:58:39 +0100 Subject: [PATCH 1/3] tagInputField_ background color --- README.md | 3 ++- TLTagsContol/TLTagsControl.h | 1 + TLTagsContol/TLTagsControl.m | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index faaf767..760cfd8 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,9 @@ In this mode control will look like below: ![Screenshot](http://storage1.static.itmages.ru/i/15/0224/h_1424800653_7670716_ed0f35f421.png) #### Setting different colors of control elements -You are able to change colors of different element by setting these prperties +You are able to change colors of different element by setting these properties ``` +@property (nonatomic, strong) UIColor *viewBackgroundColor; @property (nonatomic, strong) UIColor *tagsBackgroungColor; @property (nonatomic, strong) UIColor *tagsTextColor; @property (nonatomic, strong) UIColor *tagsDeleteButtonColor; diff --git a/TLTagsContol/TLTagsControl.h b/TLTagsContol/TLTagsControl.h index 7356d21..b730118 100644 --- a/TLTagsContol/TLTagsControl.h +++ b/TLTagsContol/TLTagsControl.h @@ -24,6 +24,7 @@ typedef NS_ENUM(NSUInteger, TLTagsControlMode) { @interface TLTagsControl : UIScrollView @property (nonatomic, strong) NSMutableArray *tags; +@property (nonatomic, strong) UIColor *viewBackgroundColor; @property (nonatomic, strong) UIColor *tagsBackgroundColor; @property (nonatomic, strong) UIColor *tagsTextColor; @property (nonatomic, strong) UIColor *tagsDeleteButtonColor; diff --git a/TLTagsContol/TLTagsControl.m b/TLTagsContol/TLTagsControl.m index 7f86a30..348009c 100644 --- a/TLTagsContol/TLTagsControl.m +++ b/TLTagsContol/TLTagsControl.m @@ -76,7 +76,9 @@ - (void)commonInit { tagInputField_ = [[UITextField alloc] initWithFrame:self.frame]; tagInputField_.layer.cornerRadius = 5; tagInputField_.layer.borderColor = [UIColor lightGrayColor].CGColor; - tagInputField_.backgroundColor = [UIColor whiteColor]; + + UIColor *BackgrounColor = _viewBackgroundColor != nil ? _viewBackgroundColor : [UIColor clearColor] ; + tagInputField_.backgroundColor = BackgrounColor; tagInputField_.delegate = self; tagInputField_.font = [UIFont fontWithName:@"HelveticaNeue" size:14]; tagInputField_.placeholder = @"tag"; From 1dab2fe75638ec7fc356706f734e94ec32268443 Mon Sep 17 00:00:00 2001 From: pierre-yves boulbin Date: Thu, 18 Feb 2016 16:09:28 +0100 Subject: [PATCH 2/3] Add Storyboard Customization --- TLTagsContol/TLTagsControl.h | 17 +++++---- TLTagsContol/TLTagsControl.m | 70 +++++++++++++++++++++++++++++------- 2 files changed, 69 insertions(+), 18 deletions(-) diff --git a/TLTagsContol/TLTagsControl.h b/TLTagsContol/TLTagsControl.h index b730118..4055819 100644 --- a/TLTagsContol/TLTagsControl.h +++ b/TLTagsContol/TLTagsControl.h @@ -12,6 +12,7 @@ @protocol TLTagsControlDelegate + - (void)tagsControl:(TLTagsControl *)tagsControl tappedAtIndex:(NSInteger)index; @end @@ -21,15 +22,19 @@ typedef NS_ENUM(NSUInteger, TLTagsControlMode) { TLTagsControlModeList, }; -@interface TLTagsControl : UIScrollView +IB_DESIGNABLE @interface TLTagsControl : UIScrollView @property (nonatomic, strong) NSMutableArray *tags; -@property (nonatomic, strong) UIColor *viewBackgroundColor; -@property (nonatomic, strong) UIColor *tagsBackgroundColor; -@property (nonatomic, strong) UIColor *tagsTextColor; -@property (nonatomic, strong) UIColor *tagsDeleteButtonColor; -@property (nonatomic, strong) NSString *tagPlaceholder; +@property (nonatomic, strong) IBInspectable UIColor *viewBackgroundColor; +@property (nonatomic, strong) IBInspectable UIColor *tagsBackgroundColor; +@property (nonatomic, strong) IBInspectable UIColor *tagsTextColor; +@property (nonatomic, strong) IBInspectable UIColor *tagsDeleteButtonColor; +@property (nonatomic, strong) IBInspectable UIColor *tagsBorderColor; +@property (nonatomic) IBInspectable CGFloat tagsBordersize; +@property (nonatomic, strong) IBInspectable NSString *tagPlaceholder; @property (nonatomic) TLTagsControlMode mode; +@property (nonatomic) IBInspectable CGFloat marginTags; +@property (nonatomic) IBInspectable CGFloat tagsCornerRadius; @property (assign, nonatomic) id tapDelegate; diff --git a/TLTagsContol/TLTagsControl.m b/TLTagsContol/TLTagsControl.m index 348009c..447569c 100644 --- a/TLTagsContol/TLTagsControl.m +++ b/TLTagsContol/TLTagsControl.m @@ -51,6 +51,8 @@ - (id)initWithFrame:(CGRect)frame andTags:(NSArray *)tags withTagsControlMode:(T return self; } + + - (id)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; @@ -69,13 +71,19 @@ - (void)awakeFromNib { - (void)commonInit { _tags = [NSMutableArray array]; - self.layer.cornerRadius = 5; + if(tagSubviews_ == nil) + tagInputField_ = [[UITextField alloc] initWithFrame:self.frame]; tagSubviews_ = [NSMutableArray array]; + //_tagsBorderColor = [UIColor clearColor]; + //_tagsBordersize = 0; - tagInputField_ = [[UITextField alloc] initWithFrame:self.frame]; - tagInputField_.layer.cornerRadius = 5; - tagInputField_.layer.borderColor = [UIColor lightGrayColor].CGColor; + CGRect frame = tagInputField_.frame; + frame.origin.y = (_marginTags / 2); + frame.size.height = frame.size.height - _marginTags; + tagInputField_.frame = frame; + tagInputField_.layer.cornerRadius = _tagsCornerRadius; + tagInputField_.layer.borderColor = [UIColor darkGrayColor].CGColor; UIColor *BackgrounColor = _viewBackgroundColor != nil ? _viewBackgroundColor : [UIColor clearColor] ; tagInputField_.backgroundColor = BackgrounColor; @@ -94,7 +102,7 @@ - (void)commonInit { - (void)layoutSubviews { [super layoutSubviews]; CGSize contentSize = self.contentSize; - CGRect frame = CGRectMake(0, 0, 100, self.frame.size.height); + CGRect frame = CGRectMake(0, 0, 100, self.frame.size.height - _marginTags); CGRect tempViewFrame; NSInteger tagIndex = 0; for (UIView *view in tagSubviews_) { @@ -104,9 +112,9 @@ - (void)layoutSubviews { UIView *prevView = tagSubviews_[index - 1]; tempViewFrame.origin.x = prevView.frame.origin.x + prevView.frame.size.width + 4; } else { - tempViewFrame.origin.x = 0; + tempViewFrame.origin.x = 7; } - tempViewFrame.origin.y = frame.origin.y; + tempViewFrame.origin.y = (_marginTags / 2); view.frame = tempViewFrame; if (_mode == TLTagsControlModeList) { @@ -124,8 +132,6 @@ - (void)layoutSubviews { if (_mode == TLTagsControlModeEdit) { frame = tagInputField_.frame; - frame.size.height = self.frame.size.height; - frame.origin.y = 0; if (tagSubviews_.count == 0) { frame.origin.x = 7; @@ -153,7 +159,7 @@ - (void)layoutSubviews { contentSize.height = self.frame.size.height; self.contentSize = contentSize; - + tagInputField_.layer.cornerRadius = _tagsCornerRadius; tagInputField_.placeholder = (_tagPlaceholder == nil) ? @"tag" : _tagPlaceholder; } @@ -209,9 +215,10 @@ - (void)reloadTagSubviews { UIView *tagView = [[UIView alloc] initWithFrame:tagInputField_.frame]; CGRect tagFrame = tagView.frame; - tagView.layer.cornerRadius = 5; - tagFrame.origin.y = tagInputField_.frame.origin.y; + tagView.layer.cornerRadius = _tagsCornerRadius; tagView.backgroundColor = tagBackgrounColor; + tagView.layer.borderColor = _tagsBorderColor.CGColor; + tagView.layer.borderWidth = _tagsBordersize; UILabel *tagLabel = [[UILabel alloc] init]; CGRect labelFrame = tagLabel.frame; @@ -368,4 +375,43 @@ - (void)gestureAction:(id)sender { [tapDelegate tagsControl:self tappedAtIndex:tapRecognizer.view.tag]; } +- (void)setTagsCornerRadius:(CGFloat)tagsCornerRadius { + _tagsCornerRadius = tagsCornerRadius; +} + +-(void) setMarginTags:(CGFloat)marginTags +{ + _marginTags = marginTags; +} + +-(void) setViewBackgroundColor:(UIColor *)viewBackgroundColor +{ + _viewBackgroundColor = viewBackgroundColor; +} + +-(void) setTagsBackgroundColor:(UIColor *)tagsBackgroundColor +{ + _tagsBackgroundColor = tagsBackgroundColor; +} + +-(void) setTagsTextColor:(UIColor *)tagsTextColor +{ + _tagsTextColor = tagsTextColor; +} + +-(void) setTagsDeleteButtonColor:(UIColor *)tagsDeleteButtonColor +{ + _tagsDeleteButtonColor = tagsDeleteButtonColor; +} + +-(void) setTagsBorderColor:(UIColor *)tagsBorderColor +{ + _tagsBorderColor = tagsBorderColor; +} + +-(void) setTagsBordersize:(CGFloat)tagsBordersize +{ + _tagsBordersize = tagsBordersize; +} + @end From 944ff07292921e99d4c6b0981cf6f4a04ed0c0e9 Mon Sep 17 00:00:00 2001 From: pierre-yves boulbin Date: Tue, 23 Feb 2016 14:06:18 +0100 Subject: [PATCH 3/3] Added Action OnClic --- TLTagsContol/TLTagsControl.h | 5 ++++- TLTagsContol/TLTagsControl.m | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/TLTagsContol/TLTagsControl.h b/TLTagsContol/TLTagsControl.h index 4055819..c0253f6 100644 --- a/TLTagsContol/TLTagsControl.h +++ b/TLTagsContol/TLTagsControl.h @@ -13,7 +13,9 @@ @protocol TLTagsControlDelegate -- (void)tagsControl:(TLTagsControl *)tagsControl tappedAtIndex:(NSInteger)index; +- (void) tagsControl:(TLTagsControl *)tagsControl tappedAtIndex:(NSInteger)index; + +- (void) actionToChooseTags:(TLTagsControl *)tagsControl; @end @@ -35,6 +37,7 @@ IB_DESIGNABLE @interface TLTagsControl : UIScrollView @property (nonatomic) TLTagsControlMode mode; @property (nonatomic) IBInspectable CGFloat marginTags; @property (nonatomic) IBInspectable CGFloat tagsCornerRadius; +@property (nonatomic) IBInspectable BOOL chooseTaggWithClic; @property (assign, nonatomic) id tapDelegate; diff --git a/TLTagsContol/TLTagsControl.m b/TLTagsContol/TLTagsControl.m index 447569c..7967c3d 100644 --- a/TLTagsContol/TLTagsControl.m +++ b/TLTagsContol/TLTagsControl.m @@ -23,6 +23,7 @@ - (instancetype)init { self = [super init]; if (self != nil) { + self.chooseTaggWithClic = NO; [self commonInit]; } @@ -75,8 +76,6 @@ - (void)commonInit { tagInputField_ = [[UITextField alloc] initWithFrame:self.frame]; tagSubviews_ = [NSMutableArray array]; - //_tagsBorderColor = [UIColor clearColor]; - //_tagsBordersize = 0; CGRect frame = tagInputField_.frame; frame.origin.y = (_marginTags / 2); @@ -310,6 +309,16 @@ - (void)tagButtonPressed:(id)sender { #pragma mark - textfield stuff +- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField +{ + if(_chooseTaggWithClic) + { + [self.tapDelegate actionToChooseTags:self]; + return NO; + } + else return YES; +} + - (BOOL)textFieldShouldReturn:(UITextField *)textField { if (textField.text.length > 0) { NSString *tag = textField.text; @@ -414,4 +423,9 @@ -(void) setTagsBordersize:(CGFloat)tagsBordersize _tagsBordersize = tagsBordersize; } +-(void) setChooseTaggWithClic:(BOOL)chooseTaggWithClic +{ + _chooseTaggWithClic = chooseTaggWithClic; +} + @end