// // YOUPAILZLabelNewCell.m // VQU // // Created by 肖浩然的mac on 2021/8/21. // Copyright © 2021 leo. All rights reserved. // #import "YOUPAILZLabelNewCell.h" @interface YOUPAILZLabelNewCell () @property (nonatomic,weak) UIButton *youpaiptitleBtn; @end @implementation YOUPAILZLabelNewCell - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self youpaifinitUI]; } return self; } - (void)youpaifinitUI{ self.contentView.layer.cornerRadius = self.contentView.size.height/2.0; self.contentView.layer.masksToBounds = YES; UIButton *titleBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [titleBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; titleBtn.titleLabel.font = LCFont12; titleBtn.backgroundColor = HexColorFromRGB(0x4F4B5B); [self.contentView addSubview:titleBtn]; self.youpaiptitleBtn = titleBtn; [titleBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.bottom.right.offset(0.0f); }]; [titleBtn addTarget:self action:@selector(didClickBtn:) forControlEvents:UIControlEventTouchUpInside]; } -(void)didClickBtn:(UIButton*)sender{ sender.selected = !sender.selected; if (self.youpaipdidselectBlock) { self.youpaipdidselectBlock(sender.selected); } if (sender.selected) { NSString *shallow = [NSString stringWithFormat:@"%@",self.youpaipmodel.youpaipstart_color]; NSString *deep = [NSString stringWithFormat:@"%@",self.youpaipmodel.youpaipover_color]; self.youpaiptitleBtn.backgroundColor = [UIColor clearColor]; [self.youpaiptitleBtn setBackgroundImage:[LCTools ColorImage:self.contentView.size FromColors:@[kColors(shallow),kColors(deep)] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal]; }else{ self.youpaiptitleBtn.backgroundColor = HexColorFromRGB(0x4F4B5B); [self.youpaiptitleBtn setBackgroundImage:nil forState:UIControlStateNormal]; } } - (void)youpaifreloadWithModel:(YOUPAIZYLabelModel *)model{ [self.youpaiptitleBtn setTitle:model.youpaipname forState:UIControlStateNormal]; // if (model.isSelect) { // NSString *shallow = [NSString stringWithFormat:@"%@",model.start_color]; // NSString *deep = [NSString stringWithFormat:@"%@",model.over_color]; // self.titleBtn.backgroundColor = [UIColor clearColor]; // [self.titleBtn setBackgroundImage:[LCTools ColorImage:self.contentView.size FromColors:@[kColors(shallow),kColors(deep)] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal]; // }else{ // self.titleBtn.backgroundColor = HexColorFromRGB(0x4F4B5B); // [self.titleBtn setBackgroundImage:nil forState:UIControlStateNormal]; // } } @end