SexViewController.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //
  2. // SexViewController.m
  3. // BuguLive
  4. //
  5. // Created by fanwe2014 on 16/7/19.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "SexViewController.h"
  9. #define imgViewHeight 80
  10. @interface SexViewController ()
  11. {
  12. UIImageView *_manImgView; //男
  13. UIImageView *_womanImgView; //女
  14. }
  15. @end
  16. @implementation SexViewController
  17. - (void)viewDidLoad
  18. {
  19. [super viewDidLoad];
  20. self.view.backgroundColor = kBackGroundColor;
  21. UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap1:)];
  22. UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap2:)];
  23. self.navigationItem.leftBarButtonItem=[UIBarButtonItem itemWithTarget:self action:@selector(backClick) image:@"com_arrow_vc_back" highImage:@"com_arrow_vc_back"];
  24. if ([self.sexType isEqualToString:@"0"] || !self.sexType)
  25. {
  26. self.sexType = @"1";
  27. }
  28. self.title = ASLocalizedString(@"性别");
  29. _manImgView = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenW/2-imgViewHeight/2, (kScreenH-240)/2-imgViewHeight/2, imgViewHeight, imgViewHeight)];
  30. _manImgView.userInteractionEnabled = YES;
  31. _manImgView.layer.cornerRadius = _manImgView.frame.size.height/2;
  32. _manImgView.layer.masksToBounds = YES;
  33. if ([self.sexType isEqualToString:@"1"])
  34. {
  35. _manImgView.image = [UIImage imageNamed:@"com_male_selected"];
  36. }else
  37. {
  38. _manImgView.image = [UIImage imageNamed:@"com_male_normal"];
  39. }
  40. [_manImgView addGestureRecognizer:tap1];
  41. [self.view addSubview:_manImgView];
  42. UILabel *sexlabel = [[UILabel alloc]initWithFrame:CGRectMake(kScreenW/2-imgViewHeight/2, (kScreenH-240)/2+imgViewHeight/2, imgViewHeight, 24)];
  43. sexlabel.textAlignment = NSTextAlignmentCenter;
  44. sexlabel.text = ASLocalizedString(@"男");
  45. sexlabel.textColor = kAppGrayColor2;
  46. sexlabel.font = [UIFont systemFontOfSize:15];
  47. [self.view addSubview:sexlabel];
  48. _womanImgView = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenW/2-imgViewHeight/2, (kScreenH-240)/2+imgViewHeight/2+50, imgViewHeight, imgViewHeight)];
  49. _womanImgView.userInteractionEnabled = YES;
  50. _womanImgView.layer.cornerRadius = _manImgView.frame.size.height/2;
  51. _womanImgView.layer.masksToBounds = YES;
  52. if ([self.sexType isEqualToString:@"2"])
  53. {
  54. _womanImgView.image = [UIImage imageNamed:@"com_female_selected"];
  55. }else
  56. {
  57. _womanImgView.image = [UIImage imageNamed:@"com_female_normal"];
  58. }
  59. [_womanImgView addGestureRecognizer:tap2];
  60. [self.view addSubview:_womanImgView];
  61. UILabel *sexlabel2 = [[UILabel alloc]initWithFrame:CGRectMake(kScreenW/2-imgViewHeight/2, (kScreenH-240)/2+imgViewHeight*3/2+50, imgViewHeight, 24)];
  62. sexlabel2.textAlignment = NSTextAlignmentCenter;
  63. sexlabel2.text = ASLocalizedString(@"女");
  64. sexlabel2.textColor = kAppGrayColor2;
  65. sexlabel2.font = [UIFont systemFontOfSize:15];
  66. [self.view addSubview:sexlabel2];
  67. }
  68. - (void)viewWillAppear:(BOOL)animated
  69. {
  70. [super viewWillAppear:animated];
  71. }
  72. - (void)viewWillDisappear:(BOOL)animated
  73. {
  74. [super viewWillDisappear:animated];
  75. }
  76. - (void)backClick
  77. {
  78. if (self.delgate)
  79. {
  80. if ([self.delgate respondsToSelector:@selector(changeSexWithString:)])
  81. {
  82. [self.delgate changeSexWithString:self.sexType];
  83. }
  84. }
  85. [self.navigationController popViewControllerAnimated:YES];
  86. }
  87. - (void)tap1:(UITapGestureRecognizer *)tap
  88. {
  89. [BGHUDHelper alert:ASLocalizedString(@"性别只能修改保存一次")];
  90. _manImgView.image = [UIImage imageNamed:@"com_male_selected"];
  91. _womanImgView.image = [UIImage imageNamed:@"com_female_normal"];
  92. self.sexType = @"1";
  93. if (self.delgate)
  94. {
  95. if ([self.delgate respondsToSelector:@selector(changeSexWithString:)])
  96. {
  97. [self.delgate changeSexWithString:self.sexType];
  98. }
  99. }
  100. [self.navigationController popViewControllerAnimated:YES];
  101. }
  102. - (void)tap2:(UITapGestureRecognizer *)tap
  103. {
  104. [BGHUDHelper alert:ASLocalizedString(@"性别只能修改保存一次")];
  105. _manImgView.image = [UIImage imageNamed:@"com_male_normal"];
  106. _womanImgView.image = [UIImage imageNamed:@"com_female_selected"];
  107. self.sexType = @"2";
  108. if (self.delgate)
  109. {
  110. if ([self.delgate respondsToSelector:@selector(changeSexWithString:)])
  111. {
  112. [self.delgate changeSexWithString:self.sexType];
  113. }
  114. }
  115. [self.navigationController popViewControllerAnimated:YES];
  116. }
  117. @end