XYCreateFansViewController.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //
  2. // XYCreateFansViewController.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2020/1/9.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYCreateFansViewController.h"
  9. #import "XYSearchApplyAgentViewController.h"
  10. #import "XYApplyAgentViewController.h"
  11. @interface XYCreateFansViewController ()<UITextFieldDelegate>
  12. @property (nonatomic, readwrite, strong) UIView *infoView;
  13. @property (nonatomic, readwrite, strong) UILabel *titleLabel;
  14. @property (nonatomic, readwrite, strong) UITextField *textField;
  15. @property (nonatomic, readwrite, strong) UIButton *sureButton;
  16. @end
  17. @implementation XYCreateFansViewController
  18. /// 重写init方法,配置你想要的属性
  19. - (instancetype)init
  20. {
  21. self = [super init];
  22. if (self) {
  23. self.prefersNavigationBarBottomLineHidden = YES;
  24. }
  25. return self;
  26. }
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. /// 设置
  30. [self _setup];
  31. /// 设置导航栏
  32. [self _setupNavigationItem];
  33. /// 设置子控件
  34. [self _setupSubViews];
  35. /// 布局子空间
  36. [self _makeSubViewsConstraints];
  37. }
  38. #pragma mark — Override
  39. - (void)bindViewModel {
  40. }
  41. #pragma mark — UITextFieldDelegate
  42. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  43. [self sureButtonAction:nil];
  44. return YES;
  45. }
  46. #pragma mark - 事件处理Or辅助方法
  47. - (void)sureButtonAction:(id)sender {
  48. if (StringIsEmpty(self.textField.text)) {
  49. [SVProgressHUD showInfoWithStatus:kLocalizedString(@"请输入粉丝团名称")];
  50. return;
  51. }
  52. [self.textField resignFirstResponder];
  53. [[XYAnchorAPIManager new] setFansNameWithFansName:self.textField.text successHandler:^(ZYLResponseModel *responseModel) {
  54. [SVProgressHUD showSuccessWithStatus:kLocalizedString(@"创建成功")];
  55. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  56. [self.navigationController popViewControllerAnimated:YES];
  57. });
  58. } failureHandler:^(ZYLNetworkError *error) {
  59. [SVProgressHUD showInfoWithStatus:error.domain];
  60. }];
  61. }
  62. #pragma mark - 初始化
  63. - (void)_setup{
  64. self.title = kLocalizedString(@"粉丝团");
  65. }
  66. #pragma mark - 设置导航栏
  67. - (void)_setupNavigationItem{
  68. }
  69. #pragma mark - 设置子控件
  70. - (void)_setupSubViews{
  71. [self.view addSubview:self.infoView];
  72. [self.infoView addSubview:self.titleLabel];
  73. [self.infoView addSubview:self.textField];
  74. [self.infoView addSubview:self.sureButton];
  75. [self.sureButton addTarget:self action:@selector(sureButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  76. }
  77. #pragma mark - 布局子控件
  78. - (void)_makeSubViewsConstraints{
  79. [self.infoView mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.top.equalTo(self.view).offset(NAVGATION_HEIGHT);
  81. make.left.right.equalTo(self.view);
  82. make.height.equalTo(@60.0f);
  83. }];
  84. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.left.equalTo(self.infoView).offset(SPACING_EDGE);
  86. make.centerY.equalTo(self.infoView);
  87. }];
  88. [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
  89. make.left.equalTo(self.titleLabel.mas_right).offset(12.0f);
  90. make.centerY.equalTo(self.infoView);
  91. make.height.equalTo(@40.0f);
  92. make.right.equalTo(self.sureButton.mas_left).offset(-10.0f);
  93. }];
  94. [self.sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
  95. make.right.equalTo(self.infoView).offset(-SPACING_EDGE);
  96. make.centerY.equalTo(self.infoView);
  97. make.width.height.equalTo(@44.0f);
  98. }];
  99. }
  100. #pragma mark - Setter & Getter
  101. - (UIView *)infoView {
  102. if (!_infoView) {
  103. _infoView = [UIView new];
  104. _infoView.backgroundColor = Color_White;
  105. }
  106. return _infoView;
  107. }
  108. - (UILabel *)titleLabel {
  109. if (!_titleLabel) {
  110. _titleLabel = [UILabel createLabelTextColor:Color_TextFont fount:Font(14)];
  111. _titleLabel.text = kLocalizedString(@"创建粉丝团");
  112. }
  113. return _titleLabel;
  114. }
  115. - (UITextField *)textField {
  116. if (!_textField) {
  117. _textField = [[UITextField alloc] init];
  118. _textField.textColor = Color_TextFont;
  119. _textField.placeholder = kLocalizedString(@"请输入粉丝团名称");
  120. _textField.font = Font(14);
  121. _textField.returnKeyType = UIReturnKeyDone;
  122. _textField.textAlignment = NSTextAlignmentRight;
  123. _textField.delegate = self;
  124. }
  125. return _textField;
  126. }
  127. - (UIButton *)sureButton {
  128. if (!_sureButton) {
  129. _sureButton = [UIButton createButtonTextColor:Color_TextRed textFont:Font(14)];
  130. [_sureButton setTitle:kLocalizedString(@"确定") forState:UIControlStateNormal];
  131. _sureButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  132. }
  133. return _sureButton;
  134. }
  135. @end