使用 View 实现的 Tag 视图,无需再使用 CollectionView
随着时间和性能复用性的考虑,本库取消了使用 AutoLayout 实现,如果您想使用支持 AutoLayout 版本,可以使用这个:https://github.com/zsk425/SKTagView
- (void)setupTagView
{
NSArray *texts = @[ @"A", @"Short", @"Button", @"Longer Button", @"Very Long Button", @"Short", @"More Button", @"Any Key"];
[texts enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop)
{
SFTag *tag = [SFTag tagWithText:obj];
tag.textColor = [UIColor blackColor];
tag.bgColor = [UIColor yellowColor];
[self.tagView addTag:tag];
}];
[self.view addSubview:self.tagView];
[self.tagView autoCenterInSuperview];
[self.tagView autoSetDimension:ALDimensionWidth toSize:220];
}
详情见图: