CNLiveBalanceView.m 2.95 KB
//
//  CNLiveBalanceView.m
//  CNLiveBalanceModule
//
//  Created by 153993236@qq.com on 11/12/2019.
//  Copyright © 2019 153993236@qq.com. All rights reserved.
//

#import "CNLiveBalanceView.h"
#import "QMUIKit.h"
#import <Masonry/Masonry.h>
#import "CNLiveCategory.h"
#import "CNLiveBaseKit.h"

@interface CNLiveBalanceView ()
@property (nonatomic, strong) UIImageView *bgView;
@property (nonatomic, strong) UILabel *title;
@property (nonatomic, strong) UIButton *balance;

@end

@implementation CNLiveBalanceView
static const NSInteger margin = 30;

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        self.userInteractionEnabled = YES;
        self.backgroundColor = [UIColor clearColor];
        [self createSubViews];
    }
    return self;
}

- (void)dealloc {
    NSLog(@"CNLiveBalanceView -- dealloc");
}

- (void)createSubViews {
    [self addSubview:self.bgView];
    [self addSubview:self.title];
    [self addSubview:self.balance];
    
    [_title mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(margin);
        make.right.equalTo(self.mas_right).with.offset(-margin);
        make.centerY.equalTo(self.mas_centerY);
        
    }];
    [_balance mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.title.mas_left);
        make.right.equalTo(self.title.mas_right);
        make.top.equalTo(self.title.mas_bottom);
        make.bottom.equalTo(self.mas_bottom).with.offset(-margin/3.0);
        
    }];
}

- (void)setNumber:(NSString *)number{
    _number = number;
    [_balance setTitle:[NSString stringWithFormat:@"¥ %@",number] forState:UIControlStateNormal];
}

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

#pragma mark - 懒加载
- (UIImageView *)bgView {
    if (!_bgView) {
        _bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)];
        _bgView.backgroundColor = [UIColor clearColor];
        UIImage *image = [self getImageWithImageName:@"balance_bg" bundleName:@"CNLiveBalanceModule" targetClass:[self class]];
        _bgView.image = image;

    }
    return _bgView;
}

- (UILabel *)title {
    if (!_title) {
        _title = [[UILabel alloc] init];
        [_title setFont:UIFontCNMake(14.0)];
        _title.textColor = [UIColor whiteColor];
        _title.text = @"账户余额(元)";
    }
    return _title;
}

- (UIButton *)balance {
    if (!_balance) {
        _balance= [UIButton buttonWithType:UIButtonTypeCustom];
        _balance.adjustsImageWhenHighlighted = NO;
        [_balance setTitle:@"¥ 0.00" forState:UIControlStateNormal];
        _balance.titleLabel.font = UIFontCNMake(50.0);
        [_balance setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    }
    return _balance;
}


@end