ModelCodeController.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // ModelCodeController.m
  3. // model
  4. //
  5. // Created by JuYi on 2018/7/20.
  6. // Copyright © 2018年 Mine. All rights reserved.
  7. // 邀请二维码界面
  8. #import "ModelCodeController.h"
  9. @interface ModelCodeController ()
  10. {
  11. NSString *invitationCode;
  12. NSString *qrcode;
  13. }
  14. @end
  15. @implementation ModelCodeController
  16. - (void)viewWillAppear:(BOOL)animated {
  17. [super viewWillAppear:animated];
  18. self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
  19. //设置导航栏透明
  20. [self.navigationController.navigationBar setTranslucent:YES];
  21. //把背景设为空
  22. [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
  23. //处理导航栏有条线的问题
  24. [self.navigationController.navigationBar setShadowImage:[UIImage new]];
  25. [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
  26. }
  27. - (void)viewWillDisappear:(BOOL)animated {
  28. [super viewWillDisappear:animated];
  29. self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
  30. //设置导航栏透明
  31. [self.navigationController.navigationBar setTranslucent:NO];
  32. // //把背景设为空
  33. [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
  34. //处理导航栏有条线的问题
  35. [self.navigationController.navigationBar setShadowImage:nil];
  36. [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]}];
  37. }
  38. - (void)viewDidLoad {
  39. [super viewDidLoad];
  40. // Do any additional setup after loading the view.
  41. self.view.backgroundColor = [UIColor whiteColor];
  42. //设置导航条
  43. [self creatNavBar];
  44. //设置子试图
  45. [self creatSubViews];
  46. }
  47. - (void)didReceiveMemoryWarning {
  48. [super didReceiveMemoryWarning];
  49. // Dispose of any resources that can be recreated.
  50. }
  51. - (void)creatNavBar {
  52. self.title = @"我的邀请码";
  53. //
  54. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  55. btn.frame = CGRectMake(0, 0, 40, 40);
  56. [btn setImage:[UIImage imageNamed:@"fanhui1"] forState:UIControlStateNormal];
  57. btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0); // backBtn2
  58. [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
  59. UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
  60. UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  61. // nagetiveSpacer.width = -12;//这个值可以根据自己需要自己调整
  62. self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem];
  63. }
  64. - (void)backClick {
  65. [self.navigationController popViewControllerAnimated:YES];
  66. }
  67. - (void)creatSubViews {
  68. UIImageView *imageView = [[UIImageView alloc] init];
  69. imageView.frame = self.view.bounds;
  70. imageView.userInteractionEnabled = YES;
  71. imageView.image = [UIImage imageNamed:@"erweimabeijing"];
  72. [self.view addSubview:imageView];
  73. NSString *pk = [ModelUser user].pk;
  74. invitationCode = [@"000000" stringByReplacingCharactersInRange:NSMakeRange(6-pk.length, pk.length) withString:pk];
  75. UILabel *codeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, ScreenHeight*560/1334, ScreenWidth, 60)];
  76. codeLabel.text = [ModelUser modelUser].qrcode;
  77. codeLabel.font = [UIFont systemFontOfSize:50];
  78. codeLabel.textAlignment = NSTextAlignmentCenter;
  79. codeLabel.textColor = RGBValueColor(0xfe4086, 1.0);
  80. [imageView addSubview:codeLabel];
  81. UIButton *copyButton = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/2-67, CGRectGetMaxY(codeLabel.frame)+20, 135, 45)];
  82. [copyButton setBackgroundImage:[UIImage imageNamed:@"fuzhianniu"] forState:UIControlStateNormal];
  83. [copyButton setTitle:@"复制" forState:UIControlStateNormal];
  84. copyButton.titleLabel.textColor = [UIColor whiteColor];
  85. copyButton.titleLabel.font = [UIFont systemFontOfSize:20];
  86. [copyButton addTarget:self action:@selector(copyCode) forControlEvents:UIControlEventTouchUpInside];
  87. [imageView addSubview:copyButton];
  88. }
  89. -(void)copyCode{
  90. UIPasteboard *pboard = [UIPasteboard generalPasteboard];
  91. pboard.string = [ModelUser modelUser].qrcode;
  92. UIAlertController *alertDialog = [UIAlertController alertControllerWithTitle:@"提示" message:@"邀请码已复制" preferredStyle:UIAlertControllerStyleAlert];
  93. UIAlertAction *laterAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  94. }];
  95. [alertDialog addAction:laterAction];
  96. [self presentViewController:alertDialog animated:YES completion:nil];
  97. }
  98. @end