| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- //
- // MORankBottomButton.m
- // MiMoLive
- //
- // Created by MiMo on 2025/9/10.
- //
- #import "MORankBottomButton.h"
- @interface MORankBottomButton ()
- @property (nonatomic, strong) UILabel *countLabel;
- @property (nonatomic, strong) UILabel *descLabel;
- @property (nonatomic, strong) UIView *coverView;//实现按下的背景色
- @end
- @implementation MORankBottomButton
- - (instancetype)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
- self.layer.cornerRadius = 20;
- self.layer.masksToBounds = YES;
-
- _iconView = [[UIImageView alloc] init];
- _iconView.tintColor = UIColor.redColor;
- [self addSubview:_iconView];
-
- _countLabel = [[UILabel alloc] init];
- _countLabel.font = [MOTextTools mediumFont:16];
- _countLabel.textColor = UIColor.blackColor;
- [self addSubview:_countLabel];
-
- _descLabel = [[UILabel alloc] init];
- _descLabel.font = [MOTextTools regularFont:12];
- _descLabel.textColor = UIColor.grayColor;
- [self addSubview:_descLabel];
-
- [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(_countLabel);
- make.right.equalTo(_countLabel.mas_left).offset(-4);
- make.width.height.mas_equalTo(20);
- }];
-
- [_countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self).offset(10);
- make.centerY.equalTo(self).offset(-8);
- }];
-
- [_descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(_countLabel.mas_bottom).offset(2);
- make.centerX.equalTo(self);
- }];
-
- [self addSubview:self.coverView];
- [self.coverView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_equalTo(0);
- }];
- }
- return self;
- }
- - (void)setHighlighted:(BOOL)highlighted {
- [super setHighlighted:highlighted];
- self.coverView.hidden = !highlighted;
- }
- - (void)configureWithCount:(NSString *)count
- desc:(NSString *)desc
- isGradient:(BOOL)isGradient {
-
- _countLabel.text = count;
- _descLabel.text = desc;
-
- if (isGradient) {
- [self layoutIfNeeded];
- // 移除之前的渐变层(避免重复添加)
- CALayer *oldLayer = [self.layer.sublayers firstObject];
- if ([oldLayer isKindOfClass:[CAGradientLayer class]]) {
- [oldLayer removeFromSuperlayer];
- }
-
- CAGradientLayer *gradient = [CAGradientLayer layer];
- gradient.frame = self.bounds;
- gradient.colors = @[(__bridge id)kBaseColorLeft.CGColor,
- (__bridge id)kBaseColorRight.CGColor];
- gradient.startPoint = CGPointMake(0, 0.5);
- gradient.endPoint = CGPointMake(1, 0.5);
- gradient.cornerRadius = self.layer.cornerRadius;
-
- [self.layer insertSublayer:gradient atIndex:0];
-
- _countLabel.textColor = UIColor.whiteColor;
- _descLabel.textColor = UIColor.whiteColor;
- } else {
- self.backgroundColor = UIColor.whiteColor;
- self.layer.borderColor = [MOTools colorWithHexString:@"#DADCE6"].CGColor;
- self.layer.borderWidth = 1;
-
- _countLabel.textColor = kBaseTextColor_1;
- _descLabel.textColor = kBaseTextColor_1;
- }
- }
- - (UIView *)coverView {
- if (!_coverView) {
- _coverView = [[UIView alloc] init];
- _coverView.backgroundColor = [MOTools colorWithHexString:@"#000000" alpha:0.2];
- _coverView.hidden = YES;
- }
- return _coverView;
- }
- @end
|