XWShareView.m
8.05 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
//
// XWShareView.m
// CNLiveScioLive
//
// Created by CNLive-zxw on 2018/10/20.
// Copyright © 2018年 CNLive. All rights reserved.
//
#import "XWShareView.h"
#import "TemplateShareManager.h"
@interface XWShareView (){
UIToolbar *_toolBar;
UIView *_contentView;
TemplateShareButton *_weiboButton;
TemplateShareButton *_weixinButton;
TemplateShareButton *_pengyouquanButton;
TemplateShareButton *_qqButton;
TemplateShareButton *_qqZoneButton;
TemplateShareButton *_txweiboButton;
TemplateShareButton *_xlweiboButton;
TemplateShareButton *_renrenButton;
TemplateShareButton *_reportButton;
NSString *_title;
NSString *_shareText;
NSString *_shareImg;
NSString *_shareUrl;
BOOL _isShowing;
}
@end
@implementation XWShareView
- (instancetype)initWithFrame:(CGRect)frame ShareImg:(NSString *)shareImg ShareTitle:(NSString *)shareTitle ShareText:(NSString *)shareText ShareUrl:(NSString *)shareUrl{
self = [super initWithFrame:frame];
if (self) {
_isShowing = YES;
_title = shareTitle;
_shareText = [self getZZwithString:shareText];
_shareImg = shareImg;
_shareUrl = shareUrl;
}
return self;
}
- (void)dealloc{
NSLog(@"%s DESTROYED-----------",__func__);
}
- (void)layoutSubviews{
[super layoutSubviews];
}
#pragma mark -- Show Method
- (void)show{
UIWindow *window = [UIApplication sharedApplication].keyWindow;
[window addSubview:self];
[self mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(window);
}];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(btnCancel)];
[self addGestureRecognizer:tap];
[self configibutton];
}
#pragma mark -- UI
- (void)configibutton{
self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
_contentView = [[UIView alloc]initWithFrame:CGRectMake(0, MainScreenHeight - 200, MainScreenWidth, 200)];
_contentView.backgroundColor = [UIColor whiteColor];
[self addSubview:_contentView];
UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(100, 15, MainScreenWidth - 200, 22)];
title.textAlignment = NSTextAlignmentCenter;
title.text = @"分享到"; //@"分享到";
title.font = Font(16);
[_contentView addSubview:title];
UIButton *close = [[UIButton alloc]initWithFrame:CGRectMake(MainScreenWidth - 44, 0, 44, 44)];
[close setImage:[UIImage imageNamed:@"cnlive_icon"] forState:UIControlStateNormal];
[close addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
[_contentView addSubview:close];
CGFloat shareWH = 80, shareMarginS = (MainScreenWidth - 3 * shareWH)/4.0;
//朋友圈
_pengyouquanButton = [TemplateShareButton buttonWithType:UIButtonTypeCustom];
_pengyouquanButton.frame = CGRectMake(shareMarginS, 80, 80, 80);
_pengyouquanButton.shareButtonType = TemplateShareButtonTypePengYouQuan;
_pengyouquanButton.image = @"朋友圈";//@"朋友圈";
[_pengyouquanButton addTarget:self action:@selector(didClickShareButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[_contentView addSubview:_pengyouquanButton];
//微信
_weixinButton = [TemplateShareButton buttonWithType:UIButtonTypeCustom];
_weixinButton.frame = CGRectMake(2 * shareMarginS + shareWH, 80, 80, 80);
_weixinButton.shareButtonType = TemplateShareButtonTypeWeiXin;
_weixinButton.image = @"微信";//@"微信";
[_weixinButton addTarget:self action:@selector(didClickShareButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[_contentView addSubview:_weixinButton];
//新浪微博
_xlweiboButton = [TemplateShareButton buttonWithType:UIButtonTypeCustom];
_xlweiboButton.frame = CGRectMake(3 * shareMarginS + 2 * shareWH, 80, 80, 80);
_xlweiboButton.shareButtonType = TemplateShareButtonTypeXLWeiBo;
// _xlweiboButton.image = CustomStr(@"Weibo");//@"新浪微博";
_xlweiboButton.image = @"新浪微博";//@"新浪微博";
[_xlweiboButton addTarget:self action:@selector(didClickShareButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[_contentView addSubview:_xlweiboButton];
}
//取消分享
- (void)dismiss{
[self removeFromSuperview];
}
#pragma mark -- Event Response
//取消分享
- (void)btnCancel{
[self removeFromSuperview];
}
- (void)didClickShareButtonAction:(TemplateShareButton *)button{
[self dismiss];
switch (button.shareButtonType) {
case TemplateShareButtonTypePengYouQuan:case TemplateShareButtonTypeWeiXin:
if ([WXApi isWXAppInstalled] && [WXApi isWXAppSupportApi]){
TemplateShareManager *manger = [TemplateShareManager shareSingleton];
[manger shareType:button.shareButtonType shareImage:_shareImg shareTitle:_title shareText:_shareText shareUrl:_shareUrl];
}
else{
//未安装微信
}
break;
case TemplateShareButtonTypeXLWeiBo:
if ([WeiboSDK isCanShareInWeiboAPP] || [WeiboSDK isCanSSOInWeiboApp]){
TemplateShareManager *manger = [TemplateShareManager shareSingleton];
[manger shareType:button.shareButtonType shareImage:_shareImg shareTitle:_title shareText:_shareText shareUrl:_shareUrl];
}
else{
//未安装新浪微博
}
break;
case TemplateShareButtonTypeQQ:case TemplateShareButtonTypeQQZone:
if ([QQApiInterface isQQInstalled]){
TemplateShareManager *manger = [TemplateShareManager shareSingleton];
[manger shareType:button.shareButtonType shareImage:_shareImg shareTitle:_title shareText:_shareText shareUrl:_shareUrl];
}
else{
//未安装qq
}
break;
default:
break;
}
}
#pragma mark - 去标签Tool
- (NSString *)getZZwithString:(NSString *)string{
if (!string || [string isEqualToString:@""] || [(NSNull *)string isEqual:[NSNull null]]) {
return @"";
}
NSRegularExpression *regularScriptExpretion=[NSRegularExpression regularExpressionWithPattern:@"<script[^>]*?>[\\s\\S]*?<\\/script>"
options:0
error:nil];
string=[regularScriptExpretion stringByReplacingMatchesInString:string options:NSMatchingReportProgress range:NSMakeRange(0, string.length) withTemplate:@""];
NSRegularExpression *regularExpretion=[NSRegularExpression regularExpressionWithPattern:@"<style[^>]*?>[\\s\\S]*?<\\/style>"
options:0
error:nil];
string=[regularExpretion stringByReplacingMatchesInString:string options:NSMatchingReportProgress range:NSMakeRange(0, string.length) withTemplate:@""];
NSRegularExpression *regularHtmlExpretion=[NSRegularExpression regularExpressionWithPattern:@"<[^>]+>"
options:0
error:nil];
string=[regularHtmlExpretion stringByReplacingMatchesInString:string options:NSMatchingReportProgress range:NSMakeRange(0, string.length) withTemplate:@""];
string = [string stringByReplacingOccurrencesOfString:@" " withString:@""]; // 过滤 等标签
return string;
}
@end