The use of iOS learning Sktagview

Source: Internet
Author: User
Tags border color

The Sktagview is a tag tag that supports automatic layout.
Characteristics:
-Flow Display Label
-Can configure label color, event, interval, margin, etc.
-Support Auto Layout
-Can be well displayed in UITableViewCell
-Support Screen switching
-Do not use Uicollectionview.

Configuration

-(void) configtagview{Self.label = [[UILabel alloc] Initwithframe:cgrectmake (10, 90, 100, 30)];    Self.label.textColor = [Uicolor blackcolor];    Self.label.font = [Uifont systemfontofsize:13];    Self.label.text = @ "Historical search";         [Self.view AddSubview:self.label];    Remove all [Self.tagview removealltags] first;    Initialize Self.tagview = [[Sktagview alloc] init];    The entire tagview corresponds to its superview upper left lower right distance self.tagView.padding = Uiedgeinsetsmake (10, 10, 10, 10);    The distance between the upper and lower lines self.tagView.lineSpacing = 10;    The distance between item self.tagView.interitemSpacing = 20; Maximum width self.tagView.preferredMaxLayoutWidth = 375;//@property (assign, nonatomic) CGFloat regularwidth; !< Fixed width//@property (nonatomic,assign) cgfloat regularheight;    !< Fixed height//original author can not add fixed width, his own modified source with fixed width and height, the default is 0, is the label layout, if implemented, then is fixed width height//self.tagView.regularWidth = 100;//    Self.tagView.regularHeight = 30; Start loading [self.datasource enumerateobjectsusingblock:^ (id _nonnull obj, nsuinteger IDX, BOOL * _nonnull stop) {//Initialize label Sktag *tag = [[Sktag alloc] initwithtext:self.datasource[idx]];        The Distance tag.padding = Uiedgeinsetsmake (3, 15, 3, 15) relative to the upper and lower right of the container.        Radian Tag.cornerradius = 3.0f;        Font tag.font = [Uifont boldsystemfontofsize:12];        Border Width tag.borderwidth = 0;        Background Tag.bgcolor = [Uicolor colorwithred:244/255.0 green:244/255.0 blue:244/255.0 alpha:1];        Border color Tag.bordercolor = [Uicolor colorwithred:191/255.0 green:191/255.0 blue:191/255.0 alpha:1];        Font Color Tag.textcolor = [Uicolor colorwithred:53/255.0 green:53/255.0 blue:53/255.0 alpha:1];        Whether you can click tag.enable = YES;    Added to Tagview [Self.tagview Addtag:tag];    }];             Click event callback Self.tagView.didTapTagAtIndex = ^ (Nsuinteger idx) {NSLog (@ "Clicked%ld", IDX);         };   Gets the intrinsic height cgfloat tagheight = self.tagView.intrinsicContentSize.height After all tags have been added; NSLog (@ "Height%lf", tagheight);    Create Frame self.tagView.frame = CGRectMake (0, 375, Tagheight) based on the intrinsic height that has been given to Sktagview;    [Self.tagview Layoutsubviews]; [Self.view AddSubview:self.tagView];}

In the Uisearchbar proxy method to implement the search when the hidden, do not search when the display

-(void) Searchbar: (Uisearchbar *) Searchbar textdidchange: (NSString *) searchtext{    NSLog (@ "%@", SearchText);     if 0 {        //  no text          = no ;         = NO;    }     Else     {        = YES;         = YES;    }}

Let's see how we can get him to be highly adaptive in the Tableviewcell.

- (void) Configcell: (Mkjtagviewtableviewcell *) cell Indexpath: (Nsindexpath *) indexpath{[Cell.tagview removealltags]; Cell.tagView.preferredMaxLayoutWidth=[UIScreen mainscreen].bounds.size.width; Cell.tagView.padding= Uiedgeinsetsmake ( -, -, -, -); Cell.tagView.lineSpacing= -; Cell.tagView.interitemSpacing= -; Cell.tagView.singleLine=NO; //give two fields, if the given is 0, then is the change, if the given is not 0, then is fixedCell.tagView.regularWidth= the; Cell.tagView.regularHeight= -; Nsarray*arr = [Self.datasource[indexpath.row] Valueforkey:@" First"]; [Arr Enumerateobjectsusingblock:^(ID_nonnull obj, Nsuinteger idx, BOOL *_nonnull stop) {Sktag*tag =[[Sktag alloc] initwithtext:arr[idx]; Tag.font= [Uifont systemfontofsize: A]; Tag.textcolor= [Uicolor colorwithred:arc4random ()% the/255.0Green:arc4random ()% the/255.0Blue:arc4random ()% the/255.0Alpha1]; Tag.bgcolor=[uicolor colorwithred:arc4random ()% the/255.0Green:arc4random ()% the/255.0Blue:arc4random ()% the/255.0Alpha1]; Tag.cornerradius=5; Tag.enable=YES; Tag.padding= Uiedgeinsetsmake (5,Ten,5,Ten);    [Cell.tagview Addtag:tag];         }]; Cell.tagView.didTapTagAtIndex= ^(Nsuinteger index) {NSLog (@"clicked%ld", index);     }; } -(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{return[TableView Fd_heightforcellwithidentifier:identyfy configuration:^ (IDcell)    {[self Configcell:cell indexpath:indexpath]; }];}

The use of iOS learning Sktagview

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.