Skip to content
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
16 changes: 16 additions & 0 deletions AMTagListView/AMTagListView.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ typedef void (^AMTagListViewTapHandler)(AMTagView*);
* -----------------------------------------------------------------------------
*/


/**
* Add tag index
*
* @param index - Tag index
*/
- (void)addTagIndex:(NSInteger)index;

/** Add a new tag
*
* Adds a new tag to the scroll view.
Expand All @@ -35,6 +43,14 @@ typedef void (^AMTagListViewTapHandler)(AMTagView*);
*/
- (void)addTags:(NSArray*)array;

/**
* Add a multiple tags and indexs
*
* @param array - array An array of strings
* @param indexs - array tags index
*/
- (void)addTags:(NSArray*)array setIndexs:(NSArray *)indexs;

/** Add a specific tag to the tag scroll view
*
* @param tagView An AMTagView instance
Expand Down
15 changes: 15 additions & 0 deletions AMTagListView/AMTagListView.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ @interface AMTagListView ()
@property (nonatomic, strong) id orientationNotification;
@property (nonatomic, strong) id tagNotification;

@property (nonatomic) NSInteger tagIndex;

@end

@implementation AMTagListView
Expand Down Expand Up @@ -61,6 +63,10 @@ - (void)setTapHandler:(AMTagListViewTapHandler)tapHandler
_tapHandler = tapHandler;
}

- (void)addTagIndex:(NSInteger)index {
_tagIndex = index;
}

- (void)addTag:(NSString*)text
{
UIFont* font = [[AMTagView appearance] textFont] ? [[AMTagView appearance] textFont] : kDefaultFont;
Expand All @@ -74,6 +80,7 @@ - (void)addTag:(NSString*)text

AMTagView* tagView = [[AMTagView alloc] initWithFrame:(CGRect){0, 0, size.width, size.height}];
[tagView setupWithText:text];
[tagView setTag:_tagIndex];
[self.tags addObject:tagView];

[self rearrangeTags];
Expand All @@ -91,6 +98,7 @@ - (void)addTagView:(AMTagView *)tagView
size.width = MIN(size.width, self.frame.size.width - self.marginX * 2);

tagView.frame = (CGRect){0, 0, size.width, size.height};
[tagView setTag:_tagIndex];
[self.tags addObject:tagView];

[self rearrangeTags];
Expand Down Expand Up @@ -132,6 +140,13 @@ - (void)rearrangeTags
[self setContentSize:(CGSize){self.frame.size.width, maxY + size.height +self.marginY}];
}

- (void)addTags:(NSArray*)array setIndexs:(NSArray *)indexs {
[indexs enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
_tagIndex = [obj integerValue];
[self addTag:[array objectAtIndex:idx]];
}];
}

- (void)addTags:(NSArray*)array
{
for (NSString* text in array) {
Expand Down
4 changes: 4 additions & 0 deletions TagListViewDemo/TagListViewDemo/AMViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ - (void)viewDidLoad
[self.tagListView addTag:@"something"];
[self.tagListView addTag:@"long tag is long"];
[self.tagListView addTag:@"hi there"];

// [[self tagListView] addTags:@[@"Hello", @"Hello people", @"Good"] setIndexs:@[@100, @200, @300]];

__weak AMViewController* weakSelf = self;
[self.tagListView setTapHandler:^(AMTagView *view) {
// NSLog(@"%@", [view tagText]);
// NSLog(@"%d", view.tag);
weakSelf.selection = view;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Delete"
message:[NSString stringWithFormat:@"Delete %@?", [view tagText]]
Expand Down