UserBindView.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //
  2. // UserBindView.m
  3. // FunSDKDemo
  4. //
  5. // Created by wujiangbo on 2018/11/2.
  6. // Copyright © 2018年 wujiangbo. All rights reserved.
  7. //
  8. #import "UserBindView.h"
  9. #import <Masonry/Masonry.h>
  10. #import "Header.h"
  11. @implementation UserBindView
  12. -(instancetype)initWithFrame:(CGRect)frame
  13. {
  14. self = [super initWithFrame:frame];
  15. if (self) {
  16. self.backgroundColor = [UIColor whiteColor];
  17. [self addSubview:self.phoneEmailTF];
  18. [self addSubview:self.codeTF];
  19. [self addSubview:self.getCodeBtn];
  20. [self addSubview:self.bindBtn];
  21. //布局
  22. [self configSubView];
  23. }
  24. return self;
  25. }
  26. #pragma mark - 控件布局
  27. -(void)configSubView
  28. {
  29. [self.phoneEmailTF mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.left.equalTo(@20);
  31. make.width.equalTo(self).offset(-40);
  32. make.height.equalTo(@40);
  33. make.top.equalTo(@84);
  34. }];
  35. [self.codeTF mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.left.equalTo(@20);
  37. make.width.equalTo(self).offset(-150);
  38. make.height.equalTo(@40);
  39. make.top.equalTo(self.phoneEmailTF.mas_bottom).offset(10);
  40. }];
  41. [self.getCodeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.left.equalTo(self.codeTF.mas_right).offset(10);
  43. make.width.equalTo(@100);
  44. make.height.equalTo(@40);
  45. make.top.equalTo(self.codeTF.mas_top);
  46. }];
  47. [self.bindBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.left.equalTo(@20);
  49. make.width.equalTo(self).offset(-40);
  50. make.height.equalTo(@40);
  51. make.top.equalTo(self.codeTF.mas_bottom).offset(20);
  52. }];
  53. }
  54. #pragma mark - button Event
  55. //绑定按钮点击
  56. -(void)bindBtnClick:(UIButton *)sender
  57. {
  58. if (self.bindBtnClicked) {
  59. self.bindBtnClicked(self.phoneEmailTF.text, self.codeTF.text);
  60. }
  61. }
  62. //获取验证码
  63. -(void)getCodeBtnClick:(UIButton *)sender
  64. {
  65. if (self.getCodeBtnClicked) {
  66. self.getCodeBtnClicked(self.phoneEmailTF.text);
  67. }
  68. }
  69. #pragma mark - lazyload 懒加载
  70. -(UITextField *)phoneEmailTF{
  71. if (!_phoneEmailTF) {
  72. _phoneEmailTF = [[UITextField alloc] init];
  73. _phoneEmailTF.layer.borderColor = [[UIColor colorWithRed:179/255.0 green:179/255.0 blue:179/255.0 alpha:1] CGColor];
  74. _phoneEmailTF.layer.borderWidth = 1;
  75. _phoneEmailTF.layer.cornerRadius = 5;
  76. _phoneEmailTF.placeholder = TS("Please_enter_your_email_address");
  77. //防止文字和边框对齐
  78. UIView *blankView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 40)];
  79. _phoneEmailTF.leftViewMode = UITextFieldViewModeAlways;
  80. blankView.backgroundColor = [UIColor clearColor];
  81. _phoneEmailTF.leftView = blankView;
  82. }
  83. return _phoneEmailTF;
  84. }
  85. -(UITextField *)codeTF{
  86. if (!_codeTF) {
  87. _codeTF = [[UITextField alloc] init];
  88. _codeTF.layer.borderColor = [[UIColor colorWithRed:179/255.0 green:179/255.0 blue:179/255.0 alpha:1] CGColor];
  89. _codeTF.placeholder = TS("input_code");
  90. _codeTF.layer.borderWidth = 1;
  91. _codeTF.layer.cornerRadius = 5;
  92. UIView *blankView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 40)];
  93. blankView.backgroundColor = [UIColor clearColor];
  94. _codeTF.leftViewMode = UITextFieldViewModeAlways;
  95. _codeTF.leftView = blankView;
  96. }
  97. return _codeTF;
  98. }
  99. -(UIButton *)getCodeBtn{
  100. if (!_getCodeBtn) {
  101. _getCodeBtn = [[UIButton alloc] init];
  102. _getCodeBtn.layer.borderColor = [[UIColor colorWithRed:179/255.0 green:179/255.0 blue:179/255.0 alpha:1] CGColor];
  103. [_getCodeBtn setTitle:TS("get_code") forState:UIControlStateNormal];
  104. _getCodeBtn.titleLabel.font = [UIFont systemFontOfSize:12];
  105. [_getCodeBtn setBackgroundColor:GlobalMainColor];
  106. _getCodeBtn.layer.cornerRadius = 5;
  107. _getCodeBtn.layer.borderWidth = 1;
  108. [_getCodeBtn addTarget:self action:@selector(getCodeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  109. }
  110. return _getCodeBtn;
  111. }
  112. -(UIButton *)bindBtn{
  113. if (!_bindBtn) {
  114. _bindBtn = [[UIButton alloc] init];
  115. [_bindBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  116. _bindBtn.titleLabel.font = [UIFont boldSystemFontOfSize:14];
  117. [_bindBtn setBackgroundColor:GlobalMainColor];
  118. _bindBtn.layer.cornerRadius = 5;
  119. [_bindBtn setTitle:TS("bind_email_address") forState:UIControlStateNormal];
  120. [_bindBtn addTarget:self action:@selector(bindBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  121. }
  122. return _bindBtn;
  123. }
  124. @end