CNLiveGroupQrCodeView.m
6.03 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
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
//
// CNLiveGroupQrCodeView.m
// CNLiveQrCodeModule
//
// Created by 153993236@qq.com on 11/12/2019.
// Copyright © 2019 153993236@qq.com. All rights reserved.
//
#import "CNLiveGroupQrCodeView.h"
#import <Masonry/Masonry.h>
#import <SDWebImage/SDWebImage.h>
#import "QMUIKit.h"
#import "SGQRCode.h"//二维码库
#import "CNUserInfoManager.h"
@interface CNLiveGroupQrCodeView()
@property (nonatomic, strong) UIImageView *groupHead;
@property (nonatomic, strong) UILabel *groupName;
@property (nonatomic, strong) UIImageView *qrcode;
@property (nonatomic, strong) UILabel *desc;
@end
@implementation CNLiveGroupQrCodeView
static const NSInteger margin = 15;
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor whiteColor];
[self createUI];
}
return self;
}
#pragma mark - UI
- (void)createUI{
[self addSubview:self.groupHead];
[self.groupHead mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self).mas_offset(margin);
make.top.mas_equalTo(self).mas_offset(margin);
make.width.mas_equalTo(36);
make.height.mas_equalTo(36);
}];
[self addSubview:self.groupName];
[self.groupName mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.groupHead.mas_right).mas_offset(margin);
make.right.mas_equalTo(self.mas_right).mas_offset(-margin);
make.top.mas_equalTo(self.groupHead.mas_top);
make.height.mas_equalTo(self.groupHead.mas_height);
}];
[self addSubview:self.qrcode];
[self.qrcode mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.mas_centerX);
make.top.mas_equalTo(self.groupName.mas_bottom).mas_offset(margin);
make.width.mas_equalTo(220.0);
make.height.mas_equalTo(220.0);
}];
[self addSubview:self.desc];
[self.desc mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.mas_left).mas_offset(margin);
make.right.mas_equalTo(self.mas_right).mas_offset(-margin);
make.top.mas_equalTo(self.qrcode.mas_bottom).mas_offset(0);
make.bottom.mas_equalTo(self.mas_bottom).mas_offset(-0);
}];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
#pragma mark - Setter
//- (void)setGroup:(IMAGroup *)group{
// _group = group;
// if(group.avatorIcon){
// _groupHead.image = group.avatorIcon;
// }else{
// [_groupHead setImageWithGroupId:group.groupInfo.groupId];
//
// }
// _groupName.text = group.groupInfo.groupName;
//
// [QMUITips showLoadingInView:self];
// [[CNGroupActiveViewModel sharedCNGroupActiveViewModel] requestServerForDownloadAppActionUrlSourceCompleterBlock:^(NSString *shareUrl) {
// [QMUITips hideAllTipsInView:self];
// NSString *wjjQr = [EncryptAndDecrypt base64StringFromText:[@{@"content":[@{@"groupId":CNLiveStringIsEmpty(group.groupInfo.groupId)?@"":group.groupInfo.groupId,@"groupName":group.groupInfo.groupName} mj_JSONString],@"type":@"groupQrType"} mj_JSONString] encryptKey:@"cnliveIm"];
// NSString *qrCode = [NSString stringWithFormat:@"%@wjjQrSkipType=wjjQrPublicGroupType&isWjjQr=%@",shareUrl,wjjQr];
// self.qrcode.image = [SGQRCodeGenerateManager generateWithLogoQRCodeData:qrCode logoImageName:nil logoScaleToSuperView:0.2];
//
// UIImage *xw_image = [self xw_getImageName:@"qr_code_icon" bundleName:@"CNLiveQrCodeModule" targetClass:[self class]];
// [strongSelf.qrCode sd_setImageWithURL:nil placeholderImage:[SGQRCodeObtain generateQRCodeWithData:jsonStr size:SCREEN_WIDTH-12*margin logoImage:xw_image ratio:0.2]];
//
// }];
//}
#pragma mark - Getter
- (UIImageView *)groupHead {
if (!_groupHead) {
_groupHead = [[UIImageView alloc] init];
_groupHead.backgroundColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
UIImage *xw_image = [self xw_getImageName:@"default_avatar_f" bundleName:@"CNLiveQrCodeModule" targetClass:[self class]];
[_groupHead sd_setImageWithURL:[NSURL URLWithString:CNUserShareModel.faceUrl] placeholderImage:xw_image];
}
return _groupHead;
}
- (UILabel *)groupName {
if (!_groupName) {
_groupName = [[UILabel alloc] init];
_groupName.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
_groupName.font = UIFontMake(15);
_groupName.numberOfLines = 1;
_groupName.text = @"张晓文";
}
return _groupName;
}
- (UIImageView *)qrcode {
if (!_qrcode) {
_qrcode = [[UIImageView alloc] init];
_qrcode.backgroundColor = [UIColor greenColor];
_qrcode.image = [SGQRCodeObtain generateQRCodeWithData:@"群组id" size:220.0 logoImage:nil ratio:0.2];
}
return _qrcode;
}
- (UILabel *)desc {
if (!_desc) {
_desc = [[UILabel alloc] init];
_desc.textColor = [UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1.0];
_desc.font = UIFontMake(15);
_desc.numberOfLines = 1;
_desc.text = @"用“网家家”扫描二维码,加入该群";
_desc.textAlignment = NSTextAlignmentCenter;
}
return _desc;
}
/**
* 创建图片
*
* @param imageName 图片名字
* @param bundleName 图片所在的bundle名字
* @param targetClass 类和bundle的同级目录
* @return 返回UIImage
*/
- (UIImage *)xw_getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{
NSBundle *bundle = [NSBundle bundleForClass:targetClass];
NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"];
NSBundle *targetBundle = [NSBundle bundleWithURL:url];
UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil];
return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil];
}
@end