Skip to content

Commit

Permalink
thank you for the pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
lijingcheng committed Jan 18, 2016
1 parent 222fc09 commit 201210f
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 46 deletions.
14 changes: 9 additions & 5 deletions Example/JCTagListView/JCViewController.m
Expand Up @@ -21,13 +21,17 @@ - (void)viewDidLoad
{
[super viewDidLoad];

self.tagListView.canSeletedTags = YES;
self.tagListView.tagColor = [UIColor darkGrayColor];
self.tagListView.canSelectTags = YES;
// self.tagListView.tagStrokeColor = [UIColor redColor];
// self.tagListView.tagBackgroundColor = [UIColor orangeColor];
// self.tagListView.tagTextColor = [UIColor greenColor];
// self.tagListView.tagSelectedBackgroundColor = [UIColor yellowColor];
self.tagListView.tagCornerRadius = 5.0f;

[self.tagListView.tags addObjectsFromArray:@[@"NSString", @"NSMutableString", @"NSArray", @"UIAlertView", @"UITapGestureRecognizer", @"IBOutlet", @"IBAction", @"id", @"UIView", @"UIStatusBar", @"UITableViewController", @"UIStepper", @"UISegmentedControl", @"UICollectionViewController", @"UISearchBar", @"UIToolbar", @"UIPageControl", @"UIActionSheet", @"NSMutableArray", @"NSDictionary", @"NSMutableDictionary", @"NSSet", @"NSMutableSet", @"NSData", @"NSMutableData", @"NSDate", @"NSCalendar", @"UIButton", @"UILabel", @"UITextField", @"UITextView", @"UIImageView", @"UITableView", @"UICollectionView", @"UIViewController"]];
[self.tagListView.selectedTags addObjectsFromArray:@[@"UIStatusBar", @"UITableViewController", @"UIStepper", @"UISegmentedControl", @"UICollectionViewController", @"UISearchBar", @"UIToolbar", @"NSMutableData", @"NSDate", @"NSCalendar", @"UIButton", @"UILabel", @"UITextField", @"UITextView", @"UIImageView", @"UITableView", @"UICollectionView", @"UIViewController"]];

[self.tagListView setCompletionBlockWithSeleted:^(NSInteger index) {
[self.tagListView setCompletionBlockWithSelected:^(NSInteger index) {
NSLog(@"______%ld______", (long)index);
}];
}
Expand All @@ -36,8 +40,8 @@ - (void)viewDidLoad

- (IBAction)delete:(id)sender
{
[self.tagListView.tags removeObjectsInArray:self.tagListView.seletedTags];
[self.tagListView.seletedTags removeAllObjects];
[self.tagListView.tags removeObjectsInArray:self.tagListView.selectedTags];
[self.tagListView.selectedTags removeAllObjects];

[self.tagListView.collectionView reloadData];
}
Expand Down
2 changes: 1 addition & 1 deletion JCTagListView.podspec
Expand Up @@ -9,7 +9,7 @@

Pod::Spec.new do |s|
s.name = "JCTagListView"
s.version = "0.0.4"
s.version = "0.0.5"
s.summary = "Support delete tags and settings tags color."
s.homepage = "http://lijingcheng.github.io/"
# s.screenshots = "www.example.com/screenshots_1", "www.example.com/screenshots_2"
Expand Down
9 changes: 4 additions & 5 deletions Pod/Classes/JCCollectionViewTagFlowLayout.m
Expand Up @@ -50,7 +50,7 @@ - (void)setup
self.minimumLineSpacing = 10.0f;
self.sectionInset = UIEdgeInsetsMake(10.0f, 10.0f, 10.0f, 10.0f);

self.itemAttributes = [[NSMutableArray alloc] initWithCapacity:10];
_itemAttributes = [NSMutableArray array];
}

#pragma mark -
Expand Down Expand Up @@ -122,11 +122,10 @@ - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
- (CGSize)itemSizeForIndexPath:(NSIndexPath *)indexPath
{
if ([self.delegate respondsToSelector:@selector(collectionView:layout:sizeForItemAtIndexPath:)]) {
return [self.delegate collectionView:self.collectionView layout:self sizeForItemAtIndexPath:indexPath];
}
else {
return self.itemSize;
self.itemSize = [self.delegate collectionView:self.collectionView layout:self sizeForItemAtIndexPath:indexPath];
}

return self.itemSize;
}

@end
8 changes: 4 additions & 4 deletions Pod/Classes/JCTagCell.m
Expand Up @@ -16,10 +16,10 @@ - (instancetype)initWithFrame:(CGRect)frame
self.layer.masksToBounds = YES;
self.layer.borderWidth = 1.0f;

self.titleLabel = [[UILabel alloc] initWithFrame:self.bounds];
self.titleLabel.textAlignment = NSTextAlignmentCenter;
self.titleLabel.font = [UIFont systemFontOfSize:14.0f];
[self.contentView addSubview:self.titleLabel];
_titleLabel = [[UILabel alloc] initWithFrame:self.bounds];
_titleLabel.textAlignment = NSTextAlignmentCenter;
_titleLabel.font = [UIFont systemFontOfSize:14.0f];
[self.contentView addSubview:_titleLabel];
}

return self;
Expand Down
13 changes: 8 additions & 5 deletions Pod/Classes/JCTagListView.h
Expand Up @@ -12,16 +12,19 @@ typedef void (^JCTagListViewBlock)(NSInteger index);

@interface JCTagListView : UIView

@property (nonatomic, strong) UIColor *tagColor;
@property (nonatomic, assign) CGFloat tagCornerRadius;
@property (nonatomic, strong) UIColor *tagStrokeColor;// default: lightGrayColor
@property (nonatomic, strong) UIColor *tagTextColor;// default: darkGrayColor
@property (nonatomic, strong) UIColor *tagBackgroundColor;// default: clearColor
@property (nonatomic, strong) UIColor *tagSelectedBackgroundColor;// default: rgb(217,217,217)

@property (nonatomic, assign) BOOL canSeletedTags;
@property (nonatomic, assign) CGFloat tagCornerRadius;// default: 10
@property (nonatomic, assign) BOOL canSelectTags;// default: NO

@property (nonatomic, strong) NSMutableArray *tags;
@property (nonatomic, strong, readonly) NSMutableArray *seletedTags;
@property (nonatomic, strong, readonly) NSMutableArray *selectedTags;

@property (nonatomic, strong) UICollectionView *collectionView;

- (void)setCompletionBlockWithSeleted:(JCTagListViewBlock)completionBlock;
- (void)setCompletionBlockWithSelected:(JCTagListViewBlock)completionBlock;

@end
59 changes: 33 additions & 26 deletions Pod/Classes/JCTagListView.m
Expand Up @@ -12,7 +12,7 @@

@interface JCTagListView ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, copy) JCTagListViewBlock seletedBlock;
@property (nonatomic, copy) JCTagListViewBlock selectedBlock;

@end

Expand Down Expand Up @@ -47,28 +47,31 @@ - (void)layoutSubviews

- (void)setup
{
_seletedTags = [NSMutableArray array];
_selectedTags = [NSMutableArray array];
_tags = [NSMutableArray array];

self.tags = [NSMutableArray array];
_tagStrokeColor = [UIColor lightGrayColor];
_tagBackgroundColor = [UIColor clearColor];
_tagTextColor = [UIColor darkGrayColor];
_tagSelectedBackgroundColor = [UIColor colorWithRed:217/255.0f green:217/255.0f blue:217/255.0f alpha:1];

self.tagColor = [UIColor darkGrayColor];
self.tagCornerRadius = 10.0f;
_tagCornerRadius = 10.0f;

JCCollectionViewTagFlowLayout *layout = [[JCCollectionViewTagFlowLayout alloc] init];

self.collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:layout];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
self.collectionView.showsHorizontalScrollIndicator = NO;
self.collectionView.showsVerticalScrollIndicator = NO;
self.collectionView.backgroundColor = [UIColor whiteColor];
[self.collectionView registerClass:[JCTagCell class] forCellWithReuseIdentifier:reuseIdentifier];
[self addSubview:self.collectionView];
_collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:layout];
_collectionView.delegate = self;
_collectionView.dataSource = self;
_collectionView.showsHorizontalScrollIndicator = NO;
_collectionView.showsVerticalScrollIndicator = NO;
_collectionView.backgroundColor = [UIColor clearColor];
[_collectionView registerClass:[JCTagCell class] forCellWithReuseIdentifier:reuseIdentifier];
[self addSubview:_collectionView];
}

- (void)setCompletionBlockWithSeleted:(JCTagListViewBlock)completionBlock
- (void)setCompletionBlockWithSelected:(JCTagListViewBlock)completionBlock
{
self.seletedBlock = completionBlock;
self.selectedBlock = completionBlock;
}

#pragma mark - UICollectionViewDelegate | UICollectionViewDataSource
Expand All @@ -91,34 +94,38 @@ - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollection
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
JCTagCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
cell.backgroundColor = [UIColor whiteColor];
cell.layer.borderColor = self.tagColor.CGColor;
cell.backgroundColor = self.tagBackgroundColor;
cell.layer.borderColor = self.tagStrokeColor.CGColor;
cell.layer.cornerRadius = self.tagCornerRadius;
cell.titleLabel.text = self.tags[indexPath.item];
cell.titleLabel.textColor = self.tagColor;
cell.titleLabel.textColor = self.tagTextColor;

if ([self.selectedTags containsObject:self.tags[indexPath.item]]) {
cell.backgroundColor = self.tagSelectedBackgroundColor;
}

return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
if (self.canSeletedTags) {
if (self.canSelectTags) {
JCTagCell *cell = (JCTagCell *)[collectionView cellForItemAtIndexPath:indexPath];

if ([_seletedTags containsObject:self.tags[indexPath.item]]) {
cell.backgroundColor = [UIColor whiteColor];
if ([self.selectedTags containsObject:self.tags[indexPath.item]]) {
cell.backgroundColor = self.tagBackgroundColor;

[_seletedTags removeObject:self.tags[indexPath.item]];
[self.selectedTags removeObject:self.tags[indexPath.item]];
}
else {
cell.backgroundColor = [UIColor colorWithRed:217/255.0f green:217/255.0f blue:217/255.0f alpha:1];
cell.backgroundColor = self.tagSelectedBackgroundColor;

[_seletedTags addObject:self.tags[indexPath.item]];
[self.selectedTags addObject:self.tags[indexPath.item]];
}
}

if (self.seletedBlock) {
self.seletedBlock(indexPath.item);
if (self.selectedBlock) {
self.selectedBlock(indexPath.item);
}
}

Expand Down

0 comments on commit 201210f

Please sign in to comment.