| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- //
- // ModelCodeController.m
- // model
- //
- // Created by JuYi on 2018/7/20.
- // Copyright © 2018年 Mine. All rights reserved.
- // 邀请二维码界面
- #import "ModelCodeController.h"
- @interface ModelCodeController ()
- {
- NSString *invitationCode;
- NSString *qrcode;
- }
- @end
- @implementation ModelCodeController
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-
- self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
- //设置导航栏透明
- [self.navigationController.navigationBar setTranslucent:YES];
- //把背景设为空
- [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
- //处理导航栏有条线的问题
- [self.navigationController.navigationBar setShadowImage:[UIImage new]];
- [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
- //设置导航栏透明
- [self.navigationController.navigationBar setTranslucent:NO];
- // //把背景设为空
- [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
- //处理导航栏有条线的问题
- [self.navigationController.navigationBar setShadowImage:nil];
- [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]}];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.view.backgroundColor = [UIColor whiteColor];
- //设置导航条
- [self creatNavBar];
- //设置子试图
- [self creatSubViews];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)creatNavBar {
- self.title = @"我的邀请码";
- //
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
- btn.frame = CGRectMake(0, 0, 40, 40);
- [btn setImage:[UIImage imageNamed:@"fanhui1"] forState:UIControlStateNormal];
- btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0); // backBtn2
- [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
- UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
- UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
- // nagetiveSpacer.width = -12;//这个值可以根据自己需要自己调整
- self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem];
- }
- - (void)backClick {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)creatSubViews {
-
- UIImageView *imageView = [[UIImageView alloc] init];
- imageView.frame = self.view.bounds;
- imageView.userInteractionEnabled = YES;
- imageView.image = [UIImage imageNamed:@"erweimabeijing"];
- [self.view addSubview:imageView];
-
- NSString *pk = [ModelUser user].pk;
- invitationCode = [@"000000" stringByReplacingCharactersInRange:NSMakeRange(6-pk.length, pk.length) withString:pk];
-
- UILabel *codeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, ScreenHeight*560/1334, ScreenWidth, 60)];
- codeLabel.text = [ModelUser modelUser].qrcode;
- codeLabel.font = [UIFont systemFontOfSize:50];
- codeLabel.textAlignment = NSTextAlignmentCenter;
- codeLabel.textColor = RGBValueColor(0xfe4086, 1.0);
- [imageView addSubview:codeLabel];
-
- UIButton *copyButton = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/2-67, CGRectGetMaxY(codeLabel.frame)+20, 135, 45)];
- [copyButton setBackgroundImage:[UIImage imageNamed:@"fuzhianniu"] forState:UIControlStateNormal];
- [copyButton setTitle:@"复制" forState:UIControlStateNormal];
- copyButton.titleLabel.textColor = [UIColor whiteColor];
- copyButton.titleLabel.font = [UIFont systemFontOfSize:20];
- [copyButton addTarget:self action:@selector(copyCode) forControlEvents:UIControlEventTouchUpInside];
- [imageView addSubview:copyButton];
- }
- -(void)copyCode{
-
- UIPasteboard *pboard = [UIPasteboard generalPasteboard];
- pboard.string = [ModelUser modelUser].qrcode;
-
- UIAlertController *alertDialog = [UIAlertController alertControllerWithTitle:@"提示" message:@"邀请码已复制" preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *laterAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
- }];
- [alertDialog addAction:laterAction];
- [self presentViewController:alertDialog animated:YES completion:nil];
- }
- @end
|