云豹科技官方教程,短视频app开发“我的名片”功能
2021年,短视频进一步完善了成熟的流量变现模式,一方面以其短小轻快、理解成本低等特征,完美迎合互联网受众,另一方面不断更新完善短视频app源码,实现更多玩法,其中,短视频app开发的“我的名片”功能就是一个很小而精的功能点。
云豹短视频app开发团队也开发了“我的名片”功能,具体是如何用代码实现的呢?一起来看看吧。
在云豹短视频app的个人中心页面,有二维码按钮,点击即可分享自己的二维码图片,邀请链接、保存图片,邀请他人通过扫码的方式下载云豹短视频app。
创建UI界面
-(void)creatUI{ backImg = [[UIImageView alloc]init]; backImg.frame = CGRectMake(16, 64+statusbarHeight+20, _window_width-32, _window_height*0.6); backImg.image = [UIImage imageNamed:@"card_bg"]; backImg.backgroundColor = Normal_BackColor; [self.view addSubview:backImg]; qrImgView = [[UIImageView alloc]init]; qrImgView.frame = CGRectMake((backImg.width-backImg.width *0.35)/2, 30, backImg.width *0.35, backImg.width *0.35); qrImgView.backgroundColor = [UIColor lightGrayColor]; [backImg addSubview:qrImgView]; UIImageView *lineImg = [[UIImageView alloc]init]; lineImg.frame = CGRectMake(backImg.width *0.2, backImg.height *0.6, backImg.width *0.6, 5); lineImg.image = [UIImage imageNamed:@"card_line"]; [backImg addSubview:lineImg]; idLb = [[UILabel alloc]init]; idLb.frame = CGRectMake(0, lineImg.top-30, backImg.width, 20); idLb.font = [UIFont systemFontOfSize:14]; idLb.text = [NSString stringWithFormat:@"ID:%@",[Config getOwnID]]; idLb.textColor = [UIColor blackColor]; idLb.textAlignment = NSTextAlignmentCenter; [backImg addSubview:idLb]; nameLb =[[UILabel alloc]init]; nameLb.frame = CGRectMake(0, idLb.top-30, backImg.width, 20); nameLb.font = [UIFont boldSystemFontOfSize:16]; nameLb.text = [Config getOwnNicename]; nameLb.textColor = [UIColor blackColor]; nameLb.textAlignment = NSTextAlignmentCenter; [backImg addSubview:nameLb]; UILabel *codeTitle = [[UILabel alloc]init]; codeTitle.frame = CGRectMake(0, lineImg.bottom+10, backImg.width, 20); codeTitle.font = [UIFont systemFontOfSize:14]; codeTitle.text = YZMsg(@"邀请码"); codeTitle.textColor = [UIColor blackColor]; codeTitle.textAlignment = NSTextAlignmentCenter; [backImg addSubview:codeTitle]; codeLb = [[UILabel alloc]init]; codeLb.frame = CGRectMake(0, codeTitle.bottom+5, backImg.width, 20); codeLb.font = [UIFont boldSystemFontOfSize:16]; codeLb.text = @"CRHDKSL"; codeLb.textColor = [UIColor blackColor]; codeLb.textAlignment = NSTextAlignmentCenter; [backImg addSubview:codeLb]; UILabel *tips = [[UILabel alloc]init]; tips.frame = CGRectMake(0, codeLb.bottom+10, backImg.width, 20); tips.font = [UIFont systemFontOfSize:14]; tips.text = YZMsg(@"扫描二维码,加我好友"); tips.textColor = [UIColor blackColor]; tips.textAlignment = NSTextAlignmentCenter; [backImg addSubview:tips]; UIView *iconView = [[UIView alloc]init]; [backImg addSubview:iconView]; [iconView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(backImg.mas_centerX); make.top.equalTo(tips.mas_bottom).offset(20); make.height.mas_equalTo(26); }]; UIImageView *iconImg = [[UIImageView alloc]init]; iconImg.image = [PublicObj getAppIcon]; iconImg.layer.cornerRadius = 5; iconImg.layer.masksToBounds = YES; [iconView addSubview:iconImg]; [iconImg mas_makeConstraints:^(MASConstraintMaker *make) { make.width.height.mas_equalTo(25); make.left.equalTo(iconView.mas_left); make.top.equalTo(iconView.mas_top); }]; UILabel *appName = [[UILabel alloc]init]; appName.font = [UIFont boldSystemFontOfSize:16]; appName.textColor = [UIColor blackColor]; appName.text =[PublicObj getAppName]; [iconView addSubview:appName]; [appName mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(iconImg.mas_right).offset(5); make.centerY.equalTo(iconImg.mas_centerY); make.right.equalTo(iconView.mas_right); }]; UIButton *saveBtn = [UIButton buttonWithType:0]; saveBtn.frame = CGRectMake(_window_width/2-40, _window_height *0.85, 70, 70); [saveBtn setImage:[UIImage imageNamed:@"card_dowloadBtn"] forState:0]; [saveBtn setTitle:YZMsg(@"保存到相册") forState:0]; saveBtn.titleLabel.font = [UIFont systemFontOfSize:13]; saveBtn = [PublicObj setUpImgDownText:saveBtn]; [saveBtn addTarget:self action:@selector(saveBtnClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:saveBtn]; }
这段短视频app源码代表:当点击保存图片时,创建一个基于位图的图形上下文并指定大小,然后把上面的子控件内容添加返回一个基于当前图形上下文的图片,然后将该图片保存
- (UIImage *)getImage:(UIView *)shareView { UIGraphicsBeginImageContextWithOptions(CGSizeMake(shareView.frame.size.width,shareView.frame.size.height ), NO, 0.0); //currentView 当前的view 创建一个基于位图的图形上下文并指定大小为 [shareView.layer renderInContext:UIGraphicsGetCurrentContext()]; // renderInContext呈现接受者及其子范围到指定的上下文 UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();//返回一个基于当前图形上下文的图片 UIGraphicsEndImageContext();//移除栈顶的基于当前位图的图形上下文 // UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);//然后将该图片保存到图片图 return viewImage; }
这段短视频app源码代表:分享链接同保存图片,获取整个view内容转换成图片,调用分享界面,分享图片
-(void)clickNaviRightBtn{ shareImage = [self getImage:backImg]; //分享 NSData *imageData = UIImagePNGRepresentation(shareImage); NSDictionary *shareDic = @{@"href":hrefStr,@"shareImage":imageData,@"shareTitle":@"扫描二维码,加我好友"}; [YBShareView showShareWithType:RKShareType_card parameter:shareDic commplete:^(int codeEvent, NSString *nums) { }]; }
以上就是通过短视频app开发实现“我的名片”功能的教程,云豹科技顺应用户潮流,不断更新云豹短视频源码已有数年之久,若您需要购买原生短视频app源码,欢迎联系云豹科技。
声明:以上内容为云豹科技作者本人原创,未经作者本人同意,禁止转载,否则将追究相关法律责任www.yunbaokj.com