// // YOUPAILZBadgeButton.m // TIANYAN // // Created by CY on 2021/5/15. // Copyright © 2021 leo. All rights reserved. // #import "YOUPAILZBadgeButton.h" @interface YOUPAILZBadgeButton () @property (nonatomic, weak) UILabel *youpaipbadgeL; @end @implementation YOUPAILZBadgeButton + (instancetype)buttonWithType:(UIButtonType)buttonType{ YOUPAILZBadgeButton *badgeBtn = [super buttonWithType:buttonType]; [badgeBtn youpaifinitUI]; [badgeBtn youpaifinitialization]; return badgeBtn; } - (instancetype)init{ if (self = [super init]) { [self youpaifinitUI]; [self youpaifinitialization]; } return self; } - (void)youpaifinitialization{ self.youpaipbadgeBgColor = HexColorFromRGB(0xF4003F); self.youpaipbadgeTextColor = [UIColor whiteColor]; self.youpaipbadgeFont = LCFont(10.0f); self.youpaipbadgeSize = CGSizeMake(14.0f, 14.0f); } - (void)youpaifinitUI{ UILabel *youpaipbadgeL = [[UILabel alloc] init]; youpaipbadgeL.hidden = YES; youpaipbadgeL.textAlignment = NSTextAlignmentCenter; [self addSubview:youpaipbadgeL]; self.youpaipbadgeL = youpaipbadgeL; [youpaipbadgeL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.mas_top).offset(0.0f); make.left.equalTo(self.mas_right).offset(-7.0f-5.0f); make.width.greaterThanOrEqualTo(0.0f); make.height.offset(0.0f); }]; } - (void)setYoupaipbadgeValue:(NSInteger)badgeValue{ _youpaipbadgeValue = badgeValue; self.youpaipbadgeL.hidden = badgeValue <= 0; self.youpaipbadgeL.text = [NSString stringWithFormat:@"%ld",badgeValue]; if (badgeValue > 99) { self.youpaipbadgeL.text = @"99+"; } } - (void)setYoupaipbadgeSize:(CGSize)youpaipbadgeSize{ _youpaipbadgeSize = youpaipbadgeSize; self.youpaipbadgeL.layer.cornerRadius = youpaipbadgeSize.width/2.0f; self.youpaipbadgeL.clipsToBounds = YES; [self.youpaipbadgeL mas_updateConstraints:^(MASConstraintMaker *make) { make.width.greaterThanOrEqualTo(youpaipbadgeSize.width); make.height.offset(youpaipbadgeSize.height); }]; } - (void)setYoupaipbadgeBgColor:(UIColor *)youpaipbadgeBgColor{ _youpaipbadgeBgColor = youpaipbadgeBgColor; self.youpaipbadgeL.backgroundColor = youpaipbadgeBgColor; } - (void)setYoupaipbadgeTextColor:(UIColor *)youpaipbadgeTextColor{ _youpaipbadgeTextColor = youpaipbadgeTextColor; self.youpaipbadgeL.textColor = youpaipbadgeTextColor; } - (void)setYoupaipbadgeFont:(UIFont *)youpaipbadgeFont{ _youpaipbadgeFont = youpaipbadgeFont; self.youpaipbadgeL.font = youpaipbadgeFont; } @end