CNLiveBalanceView.m
2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//
// 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