//
// ThirdViewController.m
// text1
//
// Created by xiaoxi on 2018/1/11.
// Copyright © 2018年 xiaoxi. All rights reserved.
//
#import "ThirdViewController.h"
#import "SliderButtonView.h"
@interface ThirdViewController ()
@property (nonatomic,strong) SliderButtonView *sliderButtonView;
@property (nonatomic,strong) UITextField *textField1;
@property (nonatomic,strong) UITextField *textField2;
@property (nonatomic,strong) UIButton *button;
@end
@implementation ThirdViewController
- (void)viewDidLoad {
[super viewDidLoad];
// self.title = @"信息查询";
self.view.backgroundColor = JMColor(245, 245, 245);
// [self createUI];
[self drawUI];
// 通知中心 *注册* 观察者
// 监听 123 频道消息
// 主要作用不是传值,而是实现相隔较远的页面之间进行交互
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveNotification:) name:@"123" object:nil];
}
/*
- (void)didReceiveNotification:(NSNotification *)sender{
JMLog(@"这是一个通知");
}
#pragma mark - 移除通知中心的观察者(首选pop)
// 如果内存控制好的话,也可以在dealloc里面写,ARC下也可以写dealloc
- (void)dealloc
{
// 移除所有的观察者
[[NSNotificationCenter defaultCenter] removeObserver:self];
// 移除指定的观察者
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"123" object:nil];
}
*/
- (void)createUI{
self.sliderButtonView = [[SliderButtonView alloc] initWithFrame:CGRectMake(0, 1 *KScale, kScreenWidth, 80 *KScale) WithButtonTitleArray:@[@"AAA",@"BBB",@"CCC"]];
[self.view addSubview:self.sliderButtonView];
}
- (void)drawUI
{
self.textField1 = [[UITextField alloc] init];
self.textField1.borderStyle = UITextBorderStyleLine;
[self.view addSubview:self.textField1];
[self.textField1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(40 *KScale);
make.right.mas_equalTo(-40 *KScale);
make.top.mas_equalTo(180 *KScale);
make.height.mas_equalTo(80 *KScale);
}];
self.textField2 = [[UITextField alloc] init];
self.textField2.borderStyle = UITextBorderStyleLine;
[self.view addSubview:self.textField2];
[self.textField2 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.textField1).offset(0);
make.right.mas_equalTo(self.textField1).offset(0);
make.top.mas_equalTo(self.textField1).offset(100 *KScale);
make.height.mas_equalTo(self.textField1);
}];
self.button = [[UIButton alloc] init];
[self.button setTitle:@"登陆" forState:UIControlStateNormal];
self.button.backgroundColor = [UIColor yellowColor];
self.button.layer.cornerRadius = 5 *KScale;
self.button.layer.borderWidth = 2 *KScale;
[self.button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
self.button.enabled = NO;
[self.button addTarget:self action:@selector(cliclkButton) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.button];
[self.button mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.textField2).offset(140 *KScale);
make.width.mas_equalTo(130 *KScale);
make.height.mas_equalTo(60 *KScale);
make.centerX.mas_equalTo(self.view.mas_centerX);
}];
[self NotificationCenter];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.view endEditing:YES];
}
//通知中心监测
- (void)NotificationCenter
{
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(texteDidChange:) name:UITextFieldTextDidChangeNotification object:nil];
}
//实现按钮状态的改变
- (void)texteDidChange:(NSNotification*)notification
{
if ([self.textField1.text isEqualToString:@""]||[self.textField2.text isEqualToString:@""]||self.textField2.text.length <6) {
self.button.enabled = NO;
}else{
self.button.enabled = YES;
[self.button setBackgroundColor:[UIColor blackColor]];
}
}
- (void)cliclkButton
{
JMLog(@"登录按钮点击");
}
@end
2018-02-25 iOS 登陆界面的简单编写(通过NSNotificationCenter)
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...