238 lines
6.4 KiB
Objective-C
238 lines
6.4 KiB
Objective-C
//
|
|
// GiGaUserJobViewCell.m
|
|
// GIGA
|
|
//
|
|
// Created by lianxiang on 2018/9/17.
|
|
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
|
//
|
|
|
|
#import "GiGaUserJobViewCell.h"
|
|
#import "JobMaskButton.h"
|
|
#define SPACE_X 8.f //横向间隔
|
|
#define SPACE_Y 8.f //纵向间隔
|
|
#define MAR_GAINX 22.f //左右边距
|
|
#define MARK_H 31.f //高
|
|
|
|
@interface GiGaUserJobViewCell()
|
|
@property (nonatomic,assign) int countY;
|
|
@property (nonatomic,assign) int countX;
|
|
@property (nonatomic,strong) NSArray *titles;
|
|
@property (nonatomic,copy) NSString *selectjob;
|
|
@end
|
|
|
|
@implementation GiGaUserJobViewCell
|
|
|
|
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
|
|
{
|
|
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
|
|
if (self) {
|
|
self.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
_countY = 0;
|
|
_countX = 0;
|
|
[self creatUI];
|
|
self.titles = [NSArray new];
|
|
//self.backgroundColor = [UIColor blueColor];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
-(void)creatUI{
|
|
|
|
[self addSubview:self.upDownBtn];
|
|
|
|
}
|
|
-(void)updateActionBtnFrame{
|
|
_upDownBtn.frame = CGRectMake(KMainW - 22 - 55,self.frame.size.height - 31, 55, 31);
|
|
|
|
}
|
|
|
|
- (UIButton *)upDownBtn{
|
|
if (!_upDownBtn) {
|
|
_upDownBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
_upDownBtn.frame = CGRectMake(KMainW - 22 - 55, 10, 55, 31);
|
|
[_upDownBtn addTarget:self action:@selector(upDownBtnAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _upDownBtn;
|
|
}
|
|
-(void)upDownBtnAction:(UIButton *)btn{
|
|
|
|
if (btn.selected) {
|
|
NSLog(@"up");
|
|
}else{
|
|
NSLog(@"down");
|
|
}
|
|
//btn.selected = btn.selected;
|
|
self.actionblock();
|
|
|
|
|
|
}
|
|
|
|
-(void)setButtnImage:(BOOL)isUp with:(NSArray *)titles{
|
|
self.titles = titles;
|
|
self.selectjob = @"";
|
|
if (isUp) {
|
|
[self setUpUPSubViewstitles:titles isUp:isUp];
|
|
|
|
}else{
|
|
[self setUpDownSubviewstitles:titles isUp:isUp];
|
|
}
|
|
}
|
|
|
|
-(void)setUpUPSubViewstitles:(NSArray *)titles isUp:(BOOL)isUp{
|
|
//展开状态
|
|
[_upDownBtn setBackgroundImage:[UIImage imageNamed:@"userjob_up"] forState:UIControlStateNormal];
|
|
if (titles.count > 0) {
|
|
for (JobMaskButton *btn in self.subviews) {
|
|
|
|
if ([btn isKindOfClass:[JobMaskButton class]]) {
|
|
[btn removeFromSuperview];
|
|
}
|
|
}
|
|
_countX =0;
|
|
_countY = 0;
|
|
CGFloat X = MAR_GAINX;
|
|
for (int i=0; i<titles.count; i ++) {
|
|
|
|
CGFloat width = 0;
|
|
NSString *title = titles[i];
|
|
if (title.length == 2) {
|
|
width = 55;
|
|
}else if (title.length == 3){
|
|
width = 68;
|
|
}else if (title.length == 4){
|
|
width = 88;
|
|
}else{
|
|
//[self makeToast:@"最小两个字"];
|
|
width = 55;
|
|
}
|
|
|
|
[self creatjob:titles[i] index:i isUp:isUp orinX:X width:width];
|
|
if (_countX == 0) {
|
|
X = MAR_GAINX;
|
|
}else{
|
|
X = X + width + SPACE_X;
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
-(void)setUpDownSubviewstitles:(NSArray *)titles isUp:(BOOL)isUp{
|
|
//收起状态
|
|
[_upDownBtn setBackgroundImage:[UIImage imageNamed:@"userjob_down"] forState:UIControlStateNormal];
|
|
if (titles.count > 0) {
|
|
// [titles enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
// NSString *title = obj;
|
|
// [self creatjob:title index:idx];
|
|
// }];
|
|
for (JobMaskButton *btn in self.subviews) {
|
|
|
|
if ([btn isKindOfClass:[JobMaskButton class]]) {
|
|
[btn removeFromSuperview];
|
|
}
|
|
}
|
|
_countX =0;
|
|
_countY = 0;
|
|
CGFloat X = MAR_GAINX;
|
|
for (int i=0; i<titles.count; i ++) {
|
|
|
|
CGFloat width = 0;
|
|
NSString *title = titles[i];
|
|
if (title.length == 2) {
|
|
width = 55;
|
|
}else if (title.length == 3){
|
|
width = 68;
|
|
}else if (title.length == 4){
|
|
width = 88;
|
|
}else{
|
|
//[self makeToast:@"最小两个字"];
|
|
width = 55;
|
|
}
|
|
|
|
[self creatjob:titles[i] index:i isUp:isUp orinX:X width:width];
|
|
|
|
if (_countX == 0) {
|
|
X = MAR_GAINX;
|
|
}else{
|
|
X = X + width + SPACE_X;
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
-(void)creatjob:(NSString *)title index:(int)idx isUp:(BOOL)isUp orinX:(CGFloat)X width:(CGFloat)width{
|
|
|
|
|
|
CGFloat Y = 10 + (MARK_H + SPACE_Y)*_countY;
|
|
_countX ++;
|
|
if (!isUp) {
|
|
|
|
//关闭状态 只展示一行
|
|
if ((X + width + SPACE_X) > (KMainW - 55 - 22)){
|
|
return;
|
|
}
|
|
|
|
}else{
|
|
|
|
if (_countY == 0) {
|
|
|
|
if ((X + width + SPACE_X) > (KMainW - 55 - 22)){
|
|
_countY ++;
|
|
_countX = 0;
|
|
}
|
|
|
|
}else{
|
|
|
|
if ((X + width + SPACE_X) > (KMainW - 22 - width)){
|
|
|
|
_countY ++;
|
|
_countX = 0;
|
|
|
|
}
|
|
if (idx == self.titles.count - 1) {
|
|
[self updateActionBtnFrame];
|
|
}
|
|
}
|
|
}
|
|
|
|
JobMaskButton *jobBtn = [JobMaskButton buttonWithType:UIButtonTypeCustom];
|
|
[jobBtn setBackgroundImage:[UIImage imageNamed:@"btn_job"] forState:UIControlStateNormal];
|
|
jobBtn.jobStr = title;
|
|
NSAttributedString *attri = [GiGaHelper stringWithText:title textColor:GIGARGB(151, 151, 151, 1) textFont:GIGA_TEXTFONTMEDIUM(13) leterSpace:0];
|
|
[jobBtn setAttributedTitle:attri forState:UIControlStateNormal];
|
|
jobBtn.frame = CGRectMake(X,Y, width, MARK_H);
|
|
[jobBtn addTarget:self action:@selector(jobClick:) forControlEvents:UIControlEventTouchUpInside];
|
|
[self addSubview:jobBtn];
|
|
|
|
}
|
|
|
|
-(void)userSelectjobAction:(jobBtnAction)block{
|
|
self.actionblock = block;
|
|
|
|
}
|
|
|
|
-(void)userSelectjob:(jobSelectAction)block{
|
|
self.jobblock = block;
|
|
}
|
|
|
|
-(void)jobClick:(JobMaskButton *)btn{
|
|
|
|
self.jobblock(btn.jobStr);
|
|
}
|
|
|
|
- (void)awakeFromNib {
|
|
[super awakeFromNib];
|
|
// Initialization code
|
|
}
|
|
|
|
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
|
|
[super setSelected:selected animated:animated];
|
|
|
|
// Configure the view for the selected state
|
|
}
|
|
|
|
@end
|