Skip to content

SKTagView is a view that supports to display tags with Autolayout.

License

Notifications You must be signed in to change notification settings

zsk425/SKTagView

This branch is 69 commits ahead of, 13 commits behind shiweifu/SFTagView:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

78916d1 · Jul 12, 2016

History

77 Commits
Feb 14, 2016
Feb 14, 2016
May 28, 2015
Jul 6, 2016
Jan 3, 2016
Jan 12, 2015
Jan 12, 2015
Jan 22, 2015
Jul 12, 2016
Jan 12, 2015
Feb 14, 2016
Jan 3, 2016
Feb 14, 2016
Jul 12, 2016

Repository files navigation

SKTagView

CI Status Version License Platform

This library is derived from SFTagView, which tries to build a view displaying tags without using UICollectionView and supports Autolayout.

I tried to make it more Autolayout. After having tried a lot, I inspired by UILabel. Now it just works like UILabel and supports single line and multi-line mode.

Installation with CocoaPods

platform :ios, '7.0'
pod "SKTagView"

Usage

Example

Check out the project. It contains the usages of normal way and in UITableViewCell.

Code

- (void)setupTagView
{
  self.tagView = ({
    SKTagView *view = [SKTagView new];
    view.backgroundColor = [UIColor cyanColor];
    view.padding = UIEdgeInsetsMake(10, 25, 10, 25);
    view.interitemSpacing = 8;
    view.lineSpacing = 10;
	//Handle tag's tap event
	view.didTapTagAtIndex = ^(NSUInteger index){
		NSLog(@"Tap");
	};
    view;
  });
  [self.view addSubview:self.tagView];
  [self.tagView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.center.equalTo(superView);
    make.leading.equalTo(superView);
    make.trailing.equalTo(superView);
  }];

  //Add Tags
  [@[@"Python", @"Javascript", @"HTML", @"Go", @"Objective-C", @"C", @"PHP"] enumerateObjectsUsingBlock:^(NSString *text, NSUInteger idx, BOOL *stop) {
    SKTag *tag = [SKTag tagWithText:text];
    tag.textColor = UIColor.whiteColor;
    tag.bgColor = UIColor.orangeColor;
    tag.cornerRadius = 3;
	tag.fontSize = 15;
	tag.padding = UIEdgeInsetsMake(13.5, 12.5, 13.5, 12.5);

    [self.tagView addTag:tag];
  }];
}

Tips

When uses with UITableViewCell in multi-line mode,it MUST be set preferredMaxLayoutWidth before invoking

[cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height + 1;

Screenshots

Normal

With UITableViewCell

License

SKTagView is available under the MIT license. See the LICENSE file for more info.

About

SKTagView is a view that supports to display tags with Autolayout.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 96.1%
  • Ruby 3.9%