Giter Site home page Giter Site logo

sktagview's Introduction

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 auto layout.It's a good beginning,but not good enough.

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

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.insets    = 5;
    view.lineSpace = 2;
	__weak SKTagView *weakView = view;
	//Handle tag's click event
	view.didClickTagAtIndex = ^(NSUInteger index){
		//Remove tag
		[weakView removeTagAtIndex:index];
	};
    view;
  });
  [self.view addSubview:self.tagView];
  [self.tagView mas_makeConstraints:^(MASConstraintMaker *make) {
    UIView *superView = self.view;
    make.center.equalTo(superView);
    make.leading.equalTo(superView.mas_leading);
    make.trailing.equalTo(superView.mas_trailing);
  }];

  //Add Tags
  [@[@"Python", @"Javascript", @"HTML", @"Go", @"Objective-C",@"C", @"PHP"] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop)
  {
    SKTag *tag = [SKTag tagWithText:obj];
    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.

sktagview's People

Contributors

akramhussein avatar jjochen avatar legranddamien avatar martinrybak avatar shiweifu avatar zsk425 avatar

Watchers

 avatar  avatar

Forkers

yueno12

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.