iOS easy-to-use label list interface Demo Effect:
Demo Demos:
1. Use the cocoapods ingest Yztaglistview or drag the folder directly into the YZTagListView project
2. Import the YZTagListView.h header file
3. Create a Yztaglistview control
| 123 |
YZTagList *tagList = [[YZTagList alloc] init]; tagList.backgroundColor = [UIColor brownColor]; _tagList = tagList; |
4. Set the Yztaglistview property (optional)
| 12345 |
// 高度可以设置为0,会自动跟随标题计算 tagList.frame = CGRectMake(0, 64, self.view.bounds.size.width, 0); // 设置标签背景色 tagList.tagBackgroundColor = [UIColor colorWithRed:20 / 255.0 green:160 / 255.0 blue:250 / 255.0 alpha:1]; // 设置标签颜色 tagList.tagColor = [UIColor whiteColor]; // 设置标签删除图片 tagList.tagDeleteimage = [UIImage imageNamed:@"chose_tag_close_icon"]; |
5. Add tags
| 12345 |
/** * 添加标签 * * @param tagStr 标签文字 */- (void)addTag:(NSString *)tagStr; |
| 12345 |
/** * 添加多个标签 * * @param tagStrs 标签数组,数组存放(NSString *) */- (void)addTags:(NSArray *)tagStrs; |
| 12345 |
/** * 删除标签 * * @param tagStr 标签文字 */- (void)deleteTag:(NSString *)tagStr; |
| 123456789 |
/** * 点击标签,执行Block */@property (nonatomic, strong) void(^clickTagBlock)(NSString *tag);列如:点击标签,删除标签 // 点击标签,就会调用 __weak typeof(_tagList) weakTagList = _tagList; _tagList.clickTagBlock = ^(NSString *tag){ [weakTagList deleteTag:tag]; }; |
| 12345 |
属性:/** * 是否需要排序功能 */@property (nonatomic, assign) BOOLisSort;/** * 在排序的时候,放大标签的比例,必须大于1 */@property (nonatomic, assign) CGFloat scaleTagInSort; |
| 123456789101112131415161718 |
实例:- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. NSArray *tags = @[@"小码哥",@"小码哥1",@"小码哥2",@"小码哥3",@"iOS学院",@"iOS学院1",@"iOS学院2",@"iOS学院3",@"吖了个峥",@"吖了个峥1",@"吖了个峥2",@"吖了个峥3"]; // 创建标签列表 YZTagList *tagList = [[YZTagList alloc] init]; // 高度可以设置为0,会自动跟随标题计算 tagList.frame = CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height - 64); // 设置排序时,缩放比例 tagList.scaleTagInSort = 1.3; // 需要排序 tagList.isSort = YES; // 标签尺寸 tagList.tagSize = CGSizeMake(80, 30); // 不需要自适应标签列表高度 tagList.isFitTagListH = NO; [self.view addSubview:tagList]; // 设置标签背景色 tagList.tagBackgroundColor = [UIColor colorWithRed:20 / 255.0 green:160 / 255.0 blue:250 / 255.0 alpha:1]; // 设置标签颜色 tagList.tagColor = [UIColor whiteColor]; /** * 这里一定先设置标签列表属性,然后最后去添加标签 */ [tagList addTags:tags];}
|
iOS easy-to-use label list interface