123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- //
- // 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
|