Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tagInputField_ background color #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 15 additions & 6 deletions TLTagsContol/TLTagsControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

@protocol TLTagsControlDelegate <NSObject>

- (void)tagsControl:(TLTagsControl *)tagsControl tappedAtIndex:(NSInteger)index;

- (void) tagsControl:(TLTagsControl *)tagsControl tappedAtIndex:(NSInteger)index;

- (void) actionToChooseTags:(TLTagsControl *)tagsControl;

@end

Expand All @@ -21,14 +24,20 @@ typedef NS_ENUM(NSUInteger, TLTagsControlMode) {
TLTagsControlModeList,
};

@interface TLTagsControl : UIScrollView
IB_DESIGNABLE @interface TLTagsControl : UIScrollView

@property (nonatomic, strong) NSMutableArray *tags;
@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 (nonatomic) IBInspectable BOOL chooseTaggWithClic;

@property (assign, nonatomic) id<TLTagsControlDelegate> tapDelegate;

Expand Down
88 changes: 75 additions & 13 deletions TLTagsContol/TLTagsControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ - (instancetype)init {
self = [super init];

if (self != nil) {
self.chooseTaggWithClic = NO;
[self commonInit];
}

Expand Down Expand Up @@ -51,6 +52,8 @@ - (id)initWithFrame:(CGRect)frame andTags:(NSArray *)tags withTagsControlMode:(T
return self;
}



- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];

Expand All @@ -69,14 +72,20 @@ - (void)awakeFromNib {
- (void)commonInit {
_tags = [NSMutableArray array];

self.layer.cornerRadius = 5;
if(tagSubviews_ == nil)
tagInputField_ = [[UITextField alloc] initWithFrame:self.frame];

tagSubviews_ = [NSMutableArray array];

tagInputField_ = [[UITextField alloc] initWithFrame:self.frame];
tagInputField_.layer.cornerRadius = 5;
tagInputField_.layer.borderColor = [UIColor lightGrayColor].CGColor;
tagInputField_.backgroundColor = [UIColor whiteColor];
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;
tagInputField_.delegate = self;
tagInputField_.font = [UIFont fontWithName:@"HelveticaNeue" size:14];
tagInputField_.placeholder = @"tag";
Expand All @@ -92,7 +101,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_) {
Expand All @@ -102,9 +111,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) {
Expand All @@ -122,8 +131,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;
Expand Down Expand Up @@ -151,7 +158,7 @@ - (void)layoutSubviews {
contentSize.height = self.frame.size.height;

self.contentSize = contentSize;

tagInputField_.layer.cornerRadius = _tagsCornerRadius;
tagInputField_.placeholder = (_tagPlaceholder == nil) ? @"tag" : _tagPlaceholder;
}

Expand Down Expand Up @@ -207,9 +214,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;
Expand Down Expand Up @@ -301,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;
Expand Down Expand Up @@ -366,4 +384,48 @@ - (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;
}

-(void) setChooseTaggWithClic:(BOOL)chooseTaggWithClic
{
_chooseTaggWithClic = chooseTaggWithClic;
}

@end