-
Notifications
You must be signed in to change notification settings - Fork 75
Open
Description
Nice control.
FYI I'm not by any means a programmer so after a few hours of banging the keyboard on trying to implement this control in storyboard UIScrollView, I wanted to let anyone struggling like me on how to implement this and capture the selected and added tags in an array...
- Add TLSTagControl.h & TLSTagControl.m in you project
- Add the to your interface
- Create an NSArray object in your interface
// This hold the array of pre-defined tags a user can select
* NSArray *customerTagArray;
-
Drag 2 UIScroll views on your storyboard and create IBOutlets for each:
// This is the UIScrollView that will populate with selected tags and new tags the user can add
-
@Property (strong, nonatomic) IBOutlet TLTagsControl *selectedTagView;
// This is the UIScrollView that provides user pre-defined tags to select
*@Property (strong, nonatomic) IBOutlet TLTagsControl *tagView;
- In your viewController.m viewDidLoad:
// This is the UIScrollView that will populate with selected tags and new tags the user can add
_selectedTagView.mode = TLTagsControlModeEdit;
_selectedTagView.tagPlaceholder = @"Add Tag";
[_selectedTagView reloadTagSubviews];
// This is the UIScrollView that provides user pre-defined tags to select
_viewCustomerTags.mode = TLTagsControlModeList;
customerTagArray = [NSMutableArray arrayWithArray:@[@"A", @"Tag", @"One", @"More", @"Tag", @"And", @"Yet", @"Another", @"One"]];
_viewCustomerTags.tags = [customerTagArray mutableCopy];
[_viewCustomerTags reloadTagSubviews];
[_viewCustomerTags setTapDelegate:self];
- In your viewController.m add this delegate method:
- (void)tagsControl:(TLTagsControl *)tagsControl tappedAtIndex:(NSInteger)index {
NSLog(@"Tag "%@" was tapped", tagsControl.tags[index]);
if (!_selectedTagView.tags containsObject:tagsControl.tags[index]]) {
[_selectedTagView.tags insertObject:tagsControl.tags[index] atIndex:0];
[_selectedTagView reloadTagSubviews];
} else {
[_selectedTagView.tags removeObject:tagsControl.tags[index]];
[_selectedTagView reloadTagSubviews];
}
}
- Your selected tags array is the _viewNewTags.tags array.
- You can add an NSLog(@"Selected Tags %@", _selectedTagView.tags); to the tagsControl method and it will show the _selectedTagView.tags array whenever user selects a pre-defined tag, however I can't figure out how to log the _selectedTagView.tags array when user adds or deletes an object.
Metadata
Metadata
Assignees
Labels
No labels