FSBodyView.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //
  2. // FSBodyView.m
  3. // MusicGradeExam
  4. //
  5. // Created by Kyle on 2020/7/14.
  6. // Copyright © 2020 DayaMusic. All rights reserved.
  7. //
  8. #import "FSBodyView.h"
  9. @interface FSBodyView ()<UITextFieldDelegate>
  10. @property (weak, nonatomic) IBOutlet UITextField *nameField;
  11. @property (weak, nonatomic) IBOutlet UITextField *passwordField;
  12. @property (weak, nonatomic) IBOutlet UITextField *sPasswordField;
  13. @property (weak, nonatomic) IBOutlet UIView *bgView;
  14. @property (nonatomic, strong) CAGradientLayer *gradientLayer;
  15. @property (nonatomic, copy) SettingCallback callback;
  16. @property (weak, nonatomic) IBOutlet UIButton *enterButton;
  17. @end
  18. @implementation FSBodyView
  19. - (void)awakeFromNib {
  20. [super awakeFromNib];
  21. self.nameField.tintColor = self.nameField.textColor;
  22. self.nameField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入用户名或学生报名姓名" attributes:@{NSForegroundColorAttributeName:HexRGBAlpha(0xffffff, 0.73), NSFontAttributeName:[UIFont systemFontOfSize:18.0]}];
  23. self.passwordField.delegate = self;
  24. self.passwordField.tintColor = self.passwordField.textColor;
  25. self.passwordField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入登录密码" attributes:@{NSForegroundColorAttributeName:HexRGBAlpha(0xffffff, 0.73), NSFontAttributeName:[UIFont systemFontOfSize:18.0]}];
  26. self.sPasswordField.delegate = self;
  27. self.sPasswordField.tintColor = self.sPasswordField.textColor;
  28. self.sPasswordField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请再次输入登录密码" attributes:@{NSForegroundColorAttributeName:HexRGB(0xffffff), NSFontAttributeName:[UIFont systemFontOfSize:18.0]}];
  29. if (@available(iOS 10.0, *)) {
  30. _passwordField.textContentType = UITextContentTypeName;
  31. _sPasswordField.textContentType = UITextContentTypeName;
  32. }
  33. [self.bgView.layer addSublayer:self.gradientLayer];
  34. self.bgView.layer.masksToBounds = YES;
  35. }
  36. + (instancetype)shareInstance {
  37. FSBodyView *view = [[[NSBundle mainBundle] loadNibNamed:@"FSBodyView" owner:nil options:nil] firstObject];
  38. return view;
  39. }
  40. - (void)settingCallback:(SettingCallback)callback {
  41. if (callback) {
  42. self.callback = callback;
  43. }
  44. }
  45. - (IBAction)backAction:(id)sender {
  46. [self endEditing:YES];
  47. if (self.callback) {
  48. self.callback(@{});
  49. }
  50. }
  51. - (IBAction)sureAction:(id)sender {
  52. [self endEditing:YES];
  53. if ([NSString isEmptyString:self.passwordField.text]) {
  54. [self MBPShow:@"请设置密码"];
  55. return;
  56. }
  57. if (self.passwordField.text.length < 6 || self.passwordField.text.length > 20) {
  58. [self MBPShow:@"密码为6-20位数字/字母"];
  59. return;
  60. }
  61. if (![self.passwordField.text isEqualToString:self.sPasswordField.text]) {
  62. [self MBPShow:@"两次输入密码不一致"];
  63. return;
  64. }
  65. if (self.callback) {
  66. self.callback(@{@"username" : self.nameField.text, @"password" : self.passwordField.text});
  67. }
  68. }
  69. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  70. if ([string isEqualToString:@"\n"]) {
  71. [self endEditing:YES];
  72. return YES;
  73. }
  74. if ([string isEqualToString:@""]) {
  75. return YES;
  76. }
  77. return YES;
  78. }
  79. - (void)textFieldDidEndEditing:(UITextField *)textField {
  80. // 判断
  81. [self checkEnterButtonStatus];
  82. }
  83. - (void)checkEnterButtonStatus {
  84. if (![NSString isEmptyString:_passwordField.text] &&![NSString isEmptyString:_sPasswordField.text]) {
  85. self.enterButton.userInteractionEnabled = YES;
  86. [self.enterButton setBackgroundImage:[UIImage imageNamed:@"login_enter"] forState:UIControlStateNormal];
  87. }
  88. else {
  89. self.enterButton.userInteractionEnabled = NO;
  90. [self.enterButton setBackgroundImage:[UIImage imageNamed:@"login_unable"] forState:UIControlStateNormal];
  91. }
  92. }
  93. - (void)layoutSubviews {
  94. [super layoutSubviews];
  95. //在这里获取frame
  96. _gradientLayer.frame = CGRectMake(0, 0, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame));
  97. }
  98. - (CAGradientLayer *)gradientLayer {
  99. if (!_gradientLayer) {
  100. _gradientLayer = [CAGradientLayer layer];
  101. _gradientLayer.startPoint = CGPointMake(0, 0.99);
  102. _gradientLayer.endPoint = CGPointMake(0, 0);
  103. _gradientLayer.locations = @[@(0),@(1.0)];//渐变点
  104. UIColor *startColor = HexRGB(0x26d9c2);
  105. UIColor *endColor = HexRGB(0x31b29a);
  106. [_gradientLayer setColors:@[(id)(startColor.CGColor),(id)(endColor.CGColor)]];//渐变数组
  107. }
  108. return _gradientLayer;
  109. }
  110. /*
  111. // Only override drawRect: if you perform custom drawing.
  112. // An empty implementation adversely affects performance during animation.
  113. - (void)drawRect:(CGRect)rect {
  114. // Drawing code
  115. }
  116. */
  117. @end