-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathRewardTipManager.m
175 lines (161 loc) · 6.45 KB
/
RewardTipManager.m
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//
// RewardTipManager.m
// Coding_iOS
//
// Created by Ease on 2016/12/14.
// Copyright © 2016年 Coding. All rights reserved.
//
#import "RewardTipManager.h"
#import "PointRecordsViewController.h"
#import "Login.h"
@interface RewardTipManager ()
@property (strong, nonatomic) NSString *title, *rewardPoint;
@property (strong, nonatomic) UIView *bgView, *contentView;
@property (strong, nonatomic) UIImageView *logoImgV;
@property (strong, nonatomic) UILabel *titleL, *rewardPointL;
@property (strong, nonatomic) UIButton *closeBtn, *knowMoreBtn;
@end
@implementation RewardTipManager
+ (instancetype)shareManager{
static RewardTipManager *shared_manager = nil;
static dispatch_once_t pred;
dispatch_once(&pred, ^{
shared_manager = [[self alloc] init];
});
return shared_manager;
}
+ (void)showTipWithTitle:(NSString *)title rewardPoint:(NSString *)rewardPoint{
if (![Login isLogin]) {
return;
}
RewardTipManager *manager = [self shareManager];
manager.title = title;
manager.rewardPoint = rewardPoint;
[manager p_show];
}
- (instancetype)init{
self = [super init];
if (self) {
//层级关系
_bgView = [UIView new];
_contentView = [UIView new];
_logoImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"reward_tip_logo"]];
_titleL = [UILabel labelWithFont:[UIFont boldSystemFontOfSize:18] textColor:[UIColor colorWithHexString:@"0x222222"]];
_rewardPointL = [UILabel labelWithSystemFontSize:15 textColorHexString:@"0x222222"];
_knowMoreBtn = ({
UIButton *button = [UIButton new];
button.backgroundColor = kColorTableSectionBg;
button.titleLabel.font = [UIFont systemFontOfSize:17];
[button setTitleColor:kColorNavTitle forState:UIControlStateNormal];
[button setTitle:@"了解码币" forState:UIControlStateNormal];
[button addTarget:self action:@selector(knowMoreBtnClicked) forControlEvents:UIControlEventTouchUpInside];
button;
});
_closeBtn = ({
UIButton *button = [UIButton new];
button.backgroundColor = kColorTableSectionBg;
button.titleLabel.font = [UIFont systemFontOfSize:17];
[button setTitleColor:kColorNavTitle forState:UIControlStateNormal];
[button setTitle:@"知道了" forState:UIControlStateNormal];
[button addTarget:self action:@selector(p_dismiss) forControlEvents:UIControlEventTouchUpInside];
button;
});
[_contentView addSubview:_logoImgV];
[_contentView addSubview:_titleL];
[_contentView addSubview:_rewardPointL];
[_contentView addSubview:_knowMoreBtn];
[_contentView addSubview:_closeBtn];
[_bgView addSubview:_contentView];
//属性设置
_contentView.backgroundColor = kColorTableSectionBg;
_contentView.layer.masksToBounds = YES;
_contentView.layer.cornerRadius = 6;
_rewardPointL.textAlignment = _titleL.textAlignment = NSTextAlignmentCenter;
_titleL.numberOfLines = 0;
//位置大小
[_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(270);
make.center.equalTo(_bgView);
}];
[_logoImgV mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(88, 67));
make.centerX.equalTo(_contentView);
make.top.equalTo(_contentView).mas_offset(30);
}];
[_titleL mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_logoImgV.mas_bottom).offset(30);
make.left.equalTo(_contentView).offset(15);
make.right.equalTo(_contentView).offset(-15);
}];
[_rewardPointL mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_titleL.mas_bottom).offset(10);
make.left.right.equalTo(_titleL);
}];
[_knowMoreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_rewardPointL.mas_bottom).offset(30);
make.left.equalTo(_contentView).offset(0);
make.bottom.equalTo(_contentView).offset(0);
make.right.equalTo(_closeBtn.mas_left).offset(0);
make.width.equalTo(_closeBtn);
make.height.mas_equalTo(44);
}];
[_closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(_contentView).offset(0);
make.top.bottom.equalTo(_knowMoreBtn);
}];
//改 UI,加两条线
UIView *hLineV = [UIView new];
UIView *vLineV = [UIView new];
hLineV.backgroundColor = vLineV.backgroundColor = kColorDDD;
[_contentView addSubview:hLineV];
[_contentView addSubview:vLineV];
[hLineV mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(_closeBtn.mas_top);
make.left.right.equalTo(_contentView);
make.height.mas_equalTo(kLine_MinHeight);
}];
[vLineV mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(_contentView);
make.top.bottom.equalTo(_closeBtn);
make.width.mas_equalTo(kLine_MinHeight);
}];
//关联事件
[_bgView bk_whenTapped:^{
[self p_dismiss];
}];
}
return self;
}
- (void)setTitle:(NSString *)title{
_title = title;
_titleL.text = _title;
}
- (void)setRewardPoint:(NSString *)rewardPoint{
_rewardPoint = rewardPoint;
[_rewardPointL setAttrStrWithStr:[NSString stringWithFormat:@"获得 %@ 的奖励", _rewardPoint] diffColorStr:_rewardPoint diffColor:[UIColor colorWithHexString:@"0xF5A623"]];
}
- (void)knowMoreBtnClicked{
PointRecordsViewController *vc = [PointRecordsViewController new];
[BaseViewController goToVC:vc];
[self p_dismiss];
}
- (void)p_show{
//初始状态
_bgView.backgroundColor = [UIColor clearColor];
_contentView.alpha = 0;
_bgView.frame = kScreen_Bounds;
[kKeyWindow addSubview:_bgView];
[UIView animateWithDuration:0.3 animations:^{
_bgView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
_contentView.alpha = 1;
} completion:nil];
}
- (void)p_dismiss{
[UIView animateWithDuration:0.3 animations:^{
_bgView.backgroundColor = [UIColor clearColor];
_contentView.alpha = 0;
} completion:^(BOOL finished) {
[_bgView removeFromSuperview];
}];
}
@end