cdts/xdts-ios 3/TreeHole/Code/Features/Settings/View/ShareInviteCodeAlertView.m

260 lines
12 KiB
Mathematica
Raw Normal View History

2023-07-27 09:20:00 +08:00
//
// ShareInviteCodeAlertView.m
// TreeHole
//
// Created by on 2022/11/13.
//
#import "ShareInviteCodeAlertView.h"
@interface ShareInviteCodeAlertView()
@property (nonatomic, strong)UIView* contentView;
@property (nonatomic, strong)UILabel* zhuanShuCodeLab;
@property (nonatomic, strong)UIImageView* inviteUnlockSmallImgV;
@property (nonatomic, strong)UIImageView* downloadImgV;
@property (nonatomic, strong)UIView* bottomView;//
@end
@implementation ShareInviteCodeAlertView
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = HEX_COLOR_A(0x000000, 0.6);
[self addSubview:self.contentView];
[self addSubview:self.bottomView];
self.contentView.transform = CGAffineTransformMakeScale(0.1, 0.1);
[UIView animateWithDuration:0.4 animations:^{
self.contentView.transform = CGAffineTransformMakeScale(1, 1);
} completion:^(BOOL finished) {
}];
}
return self;
}
-(UIView *)contentView{
if (!_contentView) {
User* userModel = [UserService currentUser];
_contentView = [[UIView alloc]initWithFrame:CGRectMake(20,(SCREEN_HEIGHT - FIX_SIZE(458))/2.0 - FIX_SIZE(40), SCREEN_WIDTH - 40, FIX_SIZE(458))];
_contentView.layer.cornerRadius = 6;
_contentView.layer.masksToBounds = YES;
_contentView.backgroundColor = HEX_COLOR(0x292247);
UIImageView* userIconImgV = [[UIImageView alloc]initWithFrame:CGRectMake(FIX_SIZE(14), FIX_SIZE(23), FIX_SIZE(46), FIX_SIZE(46))];
[userIconImgV sd_setImageWithURL:[NSURL URLWithString:userModel.avatar] placeholderImage:[UIImage imageNamed:@"TH_defalut_avatar"]];
userIconImgV.contentMode = UIViewContentModeScaleToFill;
userIconImgV.layer.cornerRadius = userIconImgV.height/2.0;
userIconImgV.layer.masksToBounds = YES;
[_contentView addSubview:userIconImgV];
UILabel* userNameLab = [[UILabel alloc]initWithFrame:CGRectMake(userIconImgV.right + FIX_SIZE(10), FIX_SIZE(20), FIX_SIZE(80), FIX_SIZE(22))];
userNameLab.textAlignment = NSTextAlignmentLeft;
userNameLab.textColor = HEX_COLOR(0xFFFFFF);
userNameLab.font = MT_FONT_MEDIUM_SIZE(16);
userNameLab.text = userModel.nickname;
[userNameLab sizeToFit];
if (userNameLab.width >= FIX_SIZE(80)) {
userNameLab.width = FIX_SIZE(80);
}
[_contentView addSubview:userNameLab];
UILabel* subTitleLab = [[UILabel alloc]initWithFrame:CGRectMake(userIconImgV.right + FIX_SIZE(10), userIconImgV.bottom - FIX_SIZE(22), FIX_SIZE(170), FIX_SIZE(17))];
subTitleLab.textAlignment = NSTextAlignmentLeft;
subTitleLab.textColor = HEX_COLOR(0xFFFFFF);
subTitleLab.font = MT_FONT_MEDIUM_SIZE(12);
subTitleLab.text = @"邀请您加入【喜蒂天使APP】";
[_contentView addSubview:subTitleLab];
UIImageView* userSexImgv = [[UIImageView alloc]initWithFrame:CGRectMake(userNameLab.right + FIX_SIZE(5), userNameLab.y + FIX_SIZE(3), FIX_SIZE(26), FIX_SIZE(16))];
if([userModel.gender_str isEqualToString:@"CD"]){
userSexImgv.image = [UIImage imageNamed:@"TH_cd_tag"];
}else if([userModel.gender_str isEqualToString:@"TS"]){
userSexImgv.image = [UIImage imageNamed:@"TH_ts_tag"];
}else{
userSexImgv.image = [UIImage imageNamed:@"TH_zn_tag"];
}
userSexImgv.contentMode = UIViewContentModeScaleToFill;
[_contentView addSubview:userSexImgv];
if (userModel.isVIP) {
userNameLab.textColor = COLOR_WITH_RGB(0xF8D07D);
UIImageView* vipImgV = [[UIImageView alloc]initWithFrame:CGRectMake(userSexImgv.right + FIX_SIZE(5), userSexImgv.y, FIX_SIZE(16), FIX_SIZE(16))];
vipImgV.image = [UIImage imageNamed:@"vip_tag"];
vipImgV.contentMode = UIViewContentModeScaleToFill;
[_contentView addSubview:vipImgV];
}else{
userNameLab.textColor = COLOR_WITH_RGB_A(0xFFFFFF, 0.9);
}
UIImageView* appLogoImgV = [[UIImageView alloc]initWithFrame:CGRectMake(_contentView.width - FIX_SIZE(14) - FIX_SIZE(65), FIX_SIZE(14), FIX_SIZE(65), FIX_SIZE(65))];
appLogoImgV.image = [UIImage imageNamed:@"appLogo1024"];
appLogoImgV.contentMode = UIViewContentModeScaleToFill;
[_contentView addSubview:appLogoImgV];
UIImageView* inviteUnlockSmallImgV = [[UIImageView alloc]initWithFrame:CGRectMake(FIX_SIZE(14), userIconImgV.bottom + FIX_SIZE(26), _contentView.width - FIX_SIZE(28), (_contentView.width - FIX_SIZE(28))*0.726 )];
inviteUnlockSmallImgV.image = [UIImage imageNamed:@"TH_invite_unlockSmallContent"];
inviteUnlockSmallImgV.contentMode = UIViewContentModeScaleToFill;
[_contentView addSubview:inviteUnlockSmallImgV];
_inviteUnlockSmallImgV = inviteUnlockSmallImgV;
UILabel* zhuanShuLab = [[UILabel alloc]initWithFrame:CGRectMake(userIconImgV.left, inviteUnlockSmallImgV.bottom + FIX_SIZE(24), FIX_SIZE(90), FIX_SIZE(22))];
zhuanShuLab.textAlignment = NSTextAlignmentLeft;
zhuanShuLab.textColor = HEX_COLOR(0xFFFFFF);
zhuanShuLab.font = MT_FONT_MEDIUM_SIZE(16);
zhuanShuLab.text = @"专属邀请码";
[_contentView addSubview:zhuanShuLab];
UILabel* zhuanShuCodeLab = [[UILabel alloc]initWithFrame:CGRectMake(zhuanShuLab.right + FIX_SIZE(5), zhuanShuLab.centerY - FIX_SIZE(13), FIX_SIZE(51), FIX_SIZE(26))];
zhuanShuCodeLab.textAlignment = NSTextAlignmentCenter;
zhuanShuCodeLab.backgroundColor = HEX_COLOR(0xEFAD01);
zhuanShuCodeLab.textColor = HEX_COLOR(0x000000);
zhuanShuCodeLab.font = MT_FONT_MEDIUM_SIZE(12);
zhuanShuCodeLab.text = @"----";
zhuanShuCodeLab.layer.cornerRadius = zhuanShuCodeLab.height / 2.0;
zhuanShuCodeLab.layer.maskedCorners = YES;
[_contentView addSubview:zhuanShuCodeLab];
_zhuanShuCodeLab = zhuanShuCodeLab;
UILabel* downloadLab = [[UILabel alloc]initWithFrame:CGRectMake(userIconImgV.left, zhuanShuLab.bottom + FIX_SIZE(21), FIX_SIZE(192), FIX_SIZE(55))];
downloadLab.textAlignment = NSTextAlignmentLeft;
downloadLab.textColor = HEX_COLOR(0xFFFFFF);
downloadLab.font = MT_FONT_MEDIUM_SIZE(12);
downloadLab.numberOfLines = 0;
downloadLab.text = @"现在扫码下载APP与圈内同友一起分享和交换照片、声音、秘密诸多惊喜和刺激等您来体验";
[_contentView addSubview:downloadLab];
UIImageView* downloadImgV = [[UIImageView alloc]initWithFrame:CGRectMake(_contentView.width - FIX_SIZE(14) - FIX_SIZE(96), inviteUnlockSmallImgV.bottom + FIX_SIZE(20), FIX_SIZE(96), FIX_SIZE(96))];
// downloadImgV.image = [UIImage imageNamed:@"TH_invite_unlockSmallContent"];
downloadImgV.backgroundColor = [UIColor whiteColor];
downloadImgV.contentMode = UIViewContentModeScaleToFill;
[_contentView addSubview:downloadImgV];
_downloadImgV = downloadImgV;
}
return _contentView;
}
-(UIView *)bottomView{
if (!_bottomView) {
_bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT - FIX_SIZE(84+44), SCREEN_WIDTH, FIX_SIZE(84+44))];
if (isIphoneX) {
_bottomView.y =SCREEN_HEIGHT - FIX_SIZE(84+44+12);
_bottomView.height = FIX_SIZE(84+44+12);
}
_bottomView.backgroundColor = HEX_COLOR(0x292247);
NSArray* shareTypeArray = @[@{@"img":@"TH_share_wx",@"title":@"微信"},
@{@"img":@"TH_share_pyq",@"title":@"朋友圈"},
@{@"img":@"TH_share_qq",@"title":@"QQ"},
@{@"img":@"TH_share_wb",@"title":@"微博"},
@{@"img":@"TH_share_hb",@"title":@"生成海报"}];
UIView* shareView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _bottomView.width, FIX_SIZE(84))];
[_bottomView addSubview:shareView];
float shareBtnW = (shareView.width - FIX_SIZE(28))/5.0;
for (NSInteger i = 0; i < shareTypeArray.count; i++) {
UIButton* shareBtn = [[UIButton alloc]initWithFrame:CGRectMake(FIX_SIZE(14) + shareBtnW*i, 0, shareBtnW, shareView.height)];
[shareBtn setTitle:shareTypeArray[i][@"title"] forState:UIControlStateNormal];
[shareBtn setTitleColor:HEX_COLOR_A(0xFFFFFF, 0) forState:UIControlStateNormal];
[shareBtn addTarget:self action:@selector(shareBtnClick:) forControlEvents:UIControlEventTouchUpInside];
[shareView addSubview:shareBtn];
UIImageView* btnImgV = [[UIImageView alloc]initWithFrame:CGRectMake((shareBtn.width - FIX_SIZE(40))/2.0, FIX_SIZE(25), FIX_SIZE(40), FIX_SIZE(40))];
btnImgV.image = [UIImage imageNamed:shareTypeArray[i][@"img"]];
[shareBtn addSubview:btnImgV];
UILabel* btnNameLab = [[UILabel alloc]initWithFrame:CGRectMake(shareBtn.left, btnImgV.bottom + FIX_SIZE(10), shareBtn.width , FIX_SIZE(14))];
btnNameLab.textAlignment = NSTextAlignmentCenter;
btnNameLab.textColor = HEX_COLOR(0xFFFFFF);
btnNameLab.font = MT_FONT_MEDIUM_SIZE(10);
btnNameLab.text = shareTypeArray[i][@"title"];
[shareView addSubview:btnNameLab];
}
UIButton* cancelBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, shareView.bottom, _bottomView.width, FIX_SIZE(44))];
[cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
[cancelBtn setTitleColor:HEX_COLOR(0xFFFFFF) forState:UIControlStateNormal];
cancelBtn.titleLabel.font = MT_FONT_MEDIUM_SIZE(12);
[cancelBtn addTarget:self action:@selector(cancelBtnClick:) forControlEvents:UIControlEventTouchUpInside];
[_bottomView addSubview:cancelBtn];
}
return _bottomView;
}
-(void)setDataDict:(NSDictionary *)dataDict{
_dataDict = dataDict;
NSDictionary* invite_vip_imgDict = _dataDict[@"invite_vip_img"];
[_inviteUnlockSmallImgV sd_setImageWithURL:[NSURL URLWithString:invite_vip_imgDict[@"invite_vip_pop_image"]] placeholderImage:[UIImage imageNamed:@"TH_invite_unlockSmallContent"]];
[_downloadImgV sd_setImageWithURL:[NSURL URLWithString:invite_vip_imgDict[@"app_url_qrcode"]] placeholderImage:[UIImage new]];
_zhuanShuCodeLab.text = _dataDict[@"invite_code"];
}
-(void)shareBtnClick:(UIButton*)sender{
NSLog(@"分享.");
if ([sender.titleLabel.text isEqualToString:@"生成海报"]) {
[self savePhoto];
return;
}
NSDictionary* invite_vip_imgDict = _dataDict[@"invite_vip_img"];
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString* download_urlStr = invite_vip_imgDict[@"download_url"];
pasteboard.string = download_urlStr;
[SVProgressHUD showSuccessWithStatus:@"已成功复制分享链接,前往对应平台粘贴发送即可~"];
}
-(void)cancelBtnClick:(UIButton*)sender{
[self removeFromSuperview];
}
// ALAssetsLibraryiOS9.0 photoliabary
-(void)savePhoto{
// 1.
// UIImage *newImage = [self rendImageWithView:[ZcqVender theTopviewControler].view];
UIImage *newImage = [self rendImageWithView:self.contentView];
// 2.
UIImageWriteToSavedPhotosAlbum(newImage, self, @selector(image:didFinishSavingWithError:contextInfo:), @"134");
}
//
- (UIImage *)rendImageWithView:(UIView *)view{
// 1.
UIGraphicsBeginImageContext(view.frame.size);
// 2.
CGContextRef ctx = UIGraphicsGetCurrentContext();
// 3.
[view.layer renderInContext:ctx];
// 4.
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
// 5.
UIGraphicsEndImageContext() ;
return newImage;
}
#pragma mark
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
if (error) {
[SVProgressHUD showErrorWithStatus:@"保存失败"];
}else{
[SVProgressHUD showSuccessWithStatus:@"保存成功"];
}
NSLog(@"%@",contextInfo);
}
@end