今天介绍一个功能齐全的的标签控件 WMZTags
控件采用链式编程,仿前端element-UI框架的标签功能
看下效果图
Untitled.gif
使用说明(简单使用,支持frame布局和masonry布局)
//frame使用
WMZTagParam *model = TagParam()
.wDataSet(@[@"标签一",@"标签二",@"标签三",@"标签四",@"标签五",@"标签六"])
.wParentViewSet(self.scrollView)
.wFrameSet(CGRectMake(10, 10, 310, 0))
WMZTags *tag1 = [[WMZTags alloc]initConfigureWithModel:model];
//masonry使用
WMZTagParam *model = TagParam()
.wDataSet(@[@"标签一",@"标签二",@"标签三",@"标签四",@"标签五",@"标签六"])
.wParentViewSet(self.scrollView)
.wMasonrySet(^(MASConstraintMaker * _Nonnull make) {
make.left.mas_equalTo(10);
make.top.mas_equalTo(CGRectGetMaxY(tag1.frame)+30);
make.width.mas_equalTo(350);
});
WMZTags *tag1 = [[WMZTags alloc]initConfigureWithModel:model];
其他用法参数说明
87A7F1EE-0566-4011-BA5C-022BD159F9FA.png
实际使用
TagParam()
//未选择的图片
.imageNameSet(@"notCheck")
//选择的图片
.selectImageNameSet(@"check")
//开启边框描边
.wHitSet(YES)
//圆角
.wRadiusSet(10)
//边框宽度
.wBoderWidthSet(1)
//边框颜色
.wBoderColorSet([UIColor cyanColor])
//未选择的文字图片(优先级高于纯图片)
.textImageNameSet(@"🐶")
//选择的文字图片
.selecTextImageNameSet(@"🐱")
//开启多选
.wSelectMoreSet(YES)
//开启新增标签
.wInsertaBleSet(YES)
//开启单选
.wSelectOneSet(YES)
//开启关闭
.wClosableSet(YES)
//开启标签换行
.wLineaBleSet(YES)
//设置标签最大行数
.wLineNumSet(0)
//设置主题
.wTypeSet(danger)
//设置标签大小
.wSizeSet(small)
//设置图文的位置
.imagePositionSet(TagImagePositionLeft)
//设置整个的背景颜色
.wBackGroundColorSet([WMZTool stringTOColor:@"#999999"])
//设置标签选中时的边框颜色
.wSelectBoderColorSet([UIColor redColor])
//设置标签选中时的标签的背景颜色
.wSelectInnerColorSet([UIColor redColor])
//设置标签选中时的文字颜色
.wSelectColorSet([UIColor redColor])
//外上边距
.marginTopSet(10)
//外下边距
.marginBottomSet(10)
//外左边距
.marginLeftSet(10)
//外右边距
.marginRightSet(10)
//内上边距
.paddingTopSet(20)
//内左边距
.paddingLeftSet(20)
//标签的左边距 (宽度)
.btnTopSet(30)
//标签的上边距 (高度)
.btnLeftSet(30)
//标签图文的间距
.btnPaddingLeftSet(5)
.wMasonrySet(^(MASConstraintMaker * _Nonnull make) {
make.left.mas_equalTo(10);
make.top.mas_equalTo(CGRectGetMaxY(tag1.frame)+30);
make.width.mas_equalTo(350);
})
.wMoreTapClick(^(NSArray * _Nonnull indexArr, NSArray * _Nonnull modelArr) {
NSLog(@"多点方法 : %@, %@",indexArr,modelArr);
})
.wTapClick(^(NSInteger index, id _Nonnull model, BOOL isSelected) {
NSLog(@"单点方法 : %ld, %@, %d",index,model,isSelected);
})
.wCloseClick(^(NSInteger index, id _Nonnull model, NSArray * _Nonnull modelArr) {
NSLog(@"关闭方法 : %ld, %@ %@",index,model,modelArr);
[weakSelf update];
})
.wInsertTextClick(^(NSString * _Nonnull text, NSArray * _Nonnull modelArr) {
NSLog(@"添加的回调 %@ %@",text,modelArr);
[weakSelf update];
})
.wInsertClick(^(NSInteger index, id _Nonnull model, InsertTextBlock _Nonnull block) {
NSLog(@"自定义添加的事件");
UIAlertController *alerVC = [UIAlertController alertControllerWithTitle:@"增加标签" message:nil preferredStyle:UIAlertControllerStyleAlert];
[alerVC addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
}];
[alerVC addAction:[UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDestructive) handler:^(UIAlertAction * _Nonnull action) {
UITextField *textfield1 = alerVC.textFields[0];
block(textfield1.text);
}]];
[self presentViewController:alerVC animated:YES completion:nil];
}} ;
介绍一下我链式写法的快捷模式,使用宏定义
.h文件
WMZPropStatementAndPropSetFuncStatement(assign, WMZTagParam, TagColorType, wType)
WMZPropStatementAndPropSetFuncStatement(assign, WMZTagParam, Boolean, wClosable)
WMZPropStatementAndPropSetFuncStatement(assign, WMZTagParam, Boolean, wInsertaBle)
WMZPropStatementAndPropSetFuncStatement(copy, WMZTagParam, NSString*, wInsertPlaceholder)
WMZPropStatementAndPropSetFuncStatement(assign, WMZTagParam, Boolean, wSelectOne)
WMZPropStatementAndPropSetFuncStatement(assign, WMZTagParam, Boolean, wSelectMore)
WMZPropStatementAndPropSetFuncStatement(assign, WMZTagParam, Boolean, wDisableTransitions)
WMZPropStatementAndPropSetFuncStatement(assign, WMZTagParam, Boolean, wHit)
WMZPropStatementAndPropSetFuncStatement(assign, WMZTagParam, Boolean, wLineaBle)
.m文件
WMZPropSetFuncImplementation(WMZTagParam, TagColorType , wType)
WMZPropSetFuncImplementation(WMZTagParam, Boolean , wClosable)
WMZPropSetFuncImplementation(WMZTagParam, Boolean, wInsertaBle)
WMZPropSetFuncImplementation(WMZTagParam, NSString*, wInsertPlaceholder)
WMZPropSetFuncImplementation(WMZTagParam, Boolean, wSelectOne)
WMZPropSetFuncImplementation(WMZTagParam, Boolean, wSelectMore)
WMZPropSetFuncImplementation(WMZTagParam, Boolean , wDisableTransitions)
WMZPropSetFuncImplementation(WMZTagParam, Boolean , wHit)
WMZPropSetFuncImplementation(WMZTagParam, Boolean, wLineaBle)
#define WMZPropStatementAndPropSetFuncStatement(propertyModifier,className, propertyPointerType, propertyName) \
@property(nonatomic,propertyModifier)propertyPointerType propertyName; \
- (className * (^) (propertyPointerType propertyName)) propertyName##Set;
#define WMZPropSetFuncImplementation(className, propertyPointerType, propertyName) \
- (className * (^) (propertyPointerType propertyName))propertyName##Set{ \
return ^(propertyPointerType propertyName) { \
_##propertyName = propertyName; \
return self; \
}; \
}
详情看demo,如果对你有用的话,前往下载demo给个star。
WMZTags










网友评论