| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- //
- // FSBodyView.m
- // MusicGradeExam
- //
- // Created by Kyle on 2020/7/14.
- // Copyright © 2020 DayaMusic. All rights reserved.
- //
- #import "FSBodyView.h"
- @interface FSBodyView ()<UITextFieldDelegate>
- @property (weak, nonatomic) IBOutlet UITextField *nameField;
- @property (weak, nonatomic) IBOutlet UITextField *passwordField;
- @property (weak, nonatomic) IBOutlet UITextField *sPasswordField;
- @property (weak, nonatomic) IBOutlet UIView *bgView;
- @property (nonatomic, strong) CAGradientLayer *gradientLayer;
- @property (nonatomic, copy) SettingCallback callback;
- @property (weak, nonatomic) IBOutlet UIButton *enterButton;
- @end
- @implementation FSBodyView
- - (void)awakeFromNib {
- [super awakeFromNib];
-
- self.nameField.tintColor = self.nameField.textColor;
- self.nameField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入用户名或学生报名姓名" attributes:@{NSForegroundColorAttributeName:HexRGBAlpha(0xffffff, 0.73), NSFontAttributeName:[UIFont systemFontOfSize:18.0]}];
-
- self.passwordField.delegate = self;
- self.passwordField.tintColor = self.passwordField.textColor;
- self.passwordField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入登录密码" attributes:@{NSForegroundColorAttributeName:HexRGBAlpha(0xffffff, 0.73), NSFontAttributeName:[UIFont systemFontOfSize:18.0]}];
-
- self.sPasswordField.delegate = self;
- self.sPasswordField.tintColor = self.sPasswordField.textColor;
- self.sPasswordField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请再次输入登录密码" attributes:@{NSForegroundColorAttributeName:HexRGB(0xffffff), NSFontAttributeName:[UIFont systemFontOfSize:18.0]}];
-
- if (@available(iOS 10.0, *)) {
- _passwordField.textContentType = UITextContentTypeName;
- _sPasswordField.textContentType = UITextContentTypeName;
- }
- [self.bgView.layer addSublayer:self.gradientLayer];
- self.bgView.layer.masksToBounds = YES;
- }
- + (instancetype)shareInstance {
- FSBodyView *view = [[[NSBundle mainBundle] loadNibNamed:@"FSBodyView" owner:nil options:nil] firstObject];
- return view;
- }
- - (void)settingCallback:(SettingCallback)callback {
- if (callback) {
- self.callback = callback;
- }
- }
- - (IBAction)backAction:(id)sender {
- [self endEditing:YES];
- if (self.callback) {
- self.callback(@{});
- }
-
- }
- - (IBAction)sureAction:(id)sender {
- [self endEditing:YES];
- if ([NSString isEmptyString:self.passwordField.text]) {
- [self MBPShow:@"请设置密码"];
- return;
- }
- if (self.passwordField.text.length < 6 || self.passwordField.text.length > 20) {
- [self MBPShow:@"密码为6-20位数字/字母"];
- return;
- }
- if (![self.passwordField.text isEqualToString:self.sPasswordField.text]) {
- [self MBPShow:@"两次输入密码不一致"];
- return;
- }
- if (self.callback) {
- self.callback(@{@"username" : self.nameField.text, @"password" : self.passwordField.text});
- }
- }
- - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
- if ([string isEqualToString:@"\n"]) {
- [self endEditing:YES];
- return YES;
- }
- if ([string isEqualToString:@""]) {
- return YES;
- }
- return YES;
- }
- - (void)textFieldDidEndEditing:(UITextField *)textField {
- // 判断
- [self checkEnterButtonStatus];
- }
- - (void)checkEnterButtonStatus {
- if (![NSString isEmptyString:_passwordField.text] &&![NSString isEmptyString:_sPasswordField.text]) {
- self.enterButton.userInteractionEnabled = YES;
- [self.enterButton setBackgroundImage:[UIImage imageNamed:@"login_enter"] forState:UIControlStateNormal];
-
- }
- else {
- self.enterButton.userInteractionEnabled = NO;
- [self.enterButton setBackgroundImage:[UIImage imageNamed:@"login_unable"] forState:UIControlStateNormal];
- }
- }
- - (void)layoutSubviews {
- [super layoutSubviews];
- //在这里获取frame
- _gradientLayer.frame = CGRectMake(0, 0, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame));
- }
- - (CAGradientLayer *)gradientLayer {
- if (!_gradientLayer) {
- _gradientLayer = [CAGradientLayer layer];
- _gradientLayer.startPoint = CGPointMake(0, 0.99);
- _gradientLayer.endPoint = CGPointMake(0, 0);
- _gradientLayer.locations = @[@(0),@(1.0)];//渐变点
- UIColor *startColor = HexRGB(0x26d9c2);
- UIColor *endColor = HexRGB(0x31b29a);
- [_gradientLayer setColors:@[(id)(startColor.CGColor),(id)(endColor.CGColor)]];//渐变数组
- }
- return _gradientLayer;
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|