OC_ 好多叠在一起的 button 封装
2018-10-08 本文已影响0人
LiYaoPeng
UIViewHandler.gif
很简单但是总是遇到这个控件,每次都写感觉好烦,就封装了一个0.0
代码点这里
用到的一些其他代码
masonry
view的链式设置
label属性的链式设置
NSMutableAttributedString属性链式处理
NSString属性链式处理
button属性的链式设置
调用
懒加载
- (FoldButtonsView *) foldButtonsView {
if (!_foldButtonsView) {
_foldButtonsView = [FoldButtonsView new];
FoldButtonsViewConfig *config = [FoldButtonsViewConfig new];
config
.setEdge(UIEdgeInsetsMake(10, 10, 10, 10))// 编剧
.setDeriction(FoldButtonsViewDerictionLeft_Right)//左对齐
.setAligment(FoldButtonsViewAligment_left)
.setFoldDistance(20)//button重叠距离
.setMaxButtonCount(5);
//设置view的基本属性
_foldButtonsView
.setConfig(config)
.setUpBorderColor(UIColor.redColor)
.setUpBorderWidth(1)
.setUpBackgroundColor(UIColor.whiteColor);
// button创建的时候会调用,只有在改变maxButtonCount 的时候,才会重新创建button
[_foldButtonsView setupButtonWhenCreatingFunc:^(NSInteger index, UIButton *button) {
}];
}
return _foldButtonsView;
}
修改foldButtonsView内部的button
[self.foldButtonsView reloadDataToIndex:8 block:^(NSInteger index, UIButton *button) {
[button setUpStyle:UIControlStateNormal style:^(UIButton *button) {
button
.setUpBackgroundImage([UIImage imageNamed:@"".addInt(index)])
.setUpBackgroundColor(UIColor.whiteColor)
.setUpTitleColor(UIColor.redColor)
.setUpBorderWidth(2)
.setUpBorderColor(UIColor.redColor)
.setUpFont([UIFont systemFontOfSize:24])
.setUpMasksToBounds(true)
.setUpCornerRadius(button.frame.size.width/2.0);
}];
}];
左对齐,左边第一个按钮在展示完全
config
.setDeriction(FoldButtonsViewDerictionLeft_Right)//左对齐
.setAligment(FoldButtonsViewAligment_left)
左对齐,右边第一个按钮在展示完全
config
.setDeriction(FoldButtonsViewDerictionRight_Left)//左对齐
.setAligment(FoldButtonsViewAligment_left)
右对齐,左边第一个按钮在展示完全
config
.setDeriction(FoldButtonsViewDerictionLeft_Right)
.setAligment(FoldButtonsViewAligment_right)
右对齐,右边第一个按钮在展示完全
config
.setDeriction(FoldButtonsViewDerictionRight_Left)
.setAligment(FoldButtonsViewAligment_right)