Skip to content

Commit

Permalink
Add actualNumberOfLines
Browse files Browse the repository at this point in the history
  • Loading branch information
zekunyan committed Nov 27, 2017
1 parent 2a5815f commit 3e66a89
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions TTGTagCollectionView/Classes/TTGTagCollectionView.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ typedef NS_ENUM(NSInteger, TTGTagCollectionAlignment) {

// Number of lines. 0 means no limit, default is 0 for vertical and 1 for horizontal.
@property (nonatomic, assign) NSUInteger numberOfLines;
// The real number of lines ignoring the numberOfLines value
@property (nonatomic, assign, readonly) NSUInteger actualNumberOfLines;

// Horizontal and vertical space between tags, default is 4.
@property (nonatomic, assign) CGFloat horizontalSpacing;
Expand Down
17 changes: 15 additions & 2 deletions TTGTagCollectionView/Classes/TTGTagCollectionView.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ @interface TTGTagCollectionView ()
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIView *containerView;
@property (nonatomic, assign) BOOL needsLayoutTagViews;
@property (nonatomic, assign) NSUInteger actualNumberOfLines;
@end

@implementation TTGTagCollectionView
Expand Down Expand Up @@ -186,7 +187,7 @@ - (void)layoutTagViewsForVerticalDirection {
currentLineX = 0;
}

// Line number limit
// Line limit
if (_numberOfLines != 0) {
UIView *tagView = [_dataSource tagCollectionView:self tagViewForIndex:i];
tagView.hidden = eachLineWidthNumbers.count >= _numberOfLines;
Expand All @@ -204,11 +205,15 @@ - (void)layoutTagViewsForVerticalDirection {
[eachLineTagCountNumbers addObject:@(currentLineTagsCount)];
[eachLineTagIndexs addObject:tmpTagIndexNumbers];

// Actual number of lines
_actualNumberOfLines = eachLineTagCountNumbers.count;

// Line limit
if (_numberOfLines != 0) {
eachLineWidthNumbers = [[eachLineWidthNumbers subarrayWithRange:NSMakeRange(0, MIN(eachLineWidthNumbers.count, _numberOfLines))] mutableCopy];
eachLineMaxHeightNumbers = [[eachLineMaxHeightNumbers subarrayWithRange:NSMakeRange(0, MIN(eachLineMaxHeightNumbers.count, _numberOfLines))] mutableCopy];
eachLineWidthNumbers = [[eachLineWidthNumbers subarrayWithRange:NSMakeRange(0, MIN(eachLineWidthNumbers.count, _numberOfLines))] mutableCopy];
eachLineTagCountNumbers = [[eachLineTagCountNumbers subarrayWithRange:NSMakeRange(0, MIN(eachLineTagCountNumbers.count, _numberOfLines))] mutableCopy];
eachLineTagIndexs = [[eachLineTagIndexs subarrayWithRange:NSMakeRange(0, MIN(eachLineTagIndexs.count, _numberOfLines))] mutableCopy];
}

// Prepare
Expand Down Expand Up @@ -405,6 +410,14 @@ - (void)setNumberOfLines:(NSUInteger)numberOfLines {
[self setNeedsLayoutTagViews];
}

- (NSUInteger)actualNumberOfLines {
if (_scrollDirection == TTGTagCollectionScrollDirectionHorizontal) {
return _numberOfLines;
} else {
return _actualNumberOfLines;
}
}

- (void)setHorizontalSpacing:(CGFloat)horizontalSpacing {
_horizontalSpacing = horizontalSpacing;
[self setNeedsLayoutTagViews];
Expand Down
2 changes: 2 additions & 0 deletions TTGTagCollectionView/Classes/TTGTextTagCollectionView.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@

// Number of lines. 0 means no limit, default is 0 for vertical and 1 for horizontal.
@property (nonatomic, assign) NSUInteger numberOfLines;
// The real number of lines ignoring the numberOfLines value
@property (nonatomic, assign, readonly) NSUInteger actualNumberOfLines;

// Tag selection limit, default is 0, means no limit
@property (nonatomic, assign) NSUInteger selectionLimit;
Expand Down
4 changes: 4 additions & 0 deletions TTGTagCollectionView/Classes/TTGTextTagCollectionView.m
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,10 @@ - (void)setNumberOfLines:(NSUInteger)numberOfLines {
_tagCollectionView.numberOfLines = numberOfLines;
}

- (NSUInteger)actualNumberOfLines {
return _tagCollectionView.actualNumberOfLines;
}

- (UIEdgeInsets)contentInset {
return _tagCollectionView.contentInset;
}
Expand Down

0 comments on commit 3e66a89

Please sign in to comment.