#import "ViewController.h"
#import "MyCellCollectionViewCell.h"
@interface ViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
{
UITextField * text;
UIButton * bt;
}
@property (nonatomic,strong) UIView *headerView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
text = [[UITextField alloc]initWithFrame:CGRectMake(50, 100, self.view.frame.size.width-100, 30)];
text.backgroundColor =[UIColor grayColor];
[self.view addSubview:text];
bt = [UIButton buttonWithType:UIButtonTypeRoundedRect];
bt.frame = CGRectMake((self.view.frame.size.width-80)/2, 150, 80, 30);
[bt setTitle:@"登陆" forState:UIControlStateNormal];
[bt setTitleColor:[UIColor redColor] forState:0];
bt.alpha = 0.5;
bt.userInteractionEnabled = NO;
[bt addTarget:self action:@selector(Btn:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:bt];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(change:) name:UITextFieldTextDidChangeNotification object:text];
}
-(void)change:(NSNotification *)notification
{
if (text.text.length > 0) {
bt.userInteractionEnabled = YES;
[bt setTitleColor:[UIColor redColor] forState:0];
bt.alpha = 1;
// NSLog(@"内容大于0可以点击");
}else
{
bt.userInteractionEnabled = NO;
[bt setTitleColor:[UIColor redColor] forState:0];
bt.alpha = 0.5;
// NSLog(@"内容为空不可点击");
}
}
-(void)Btn:(UIButton * )sender
{
if (text.text.length > 0)
{
NSLog(@"内容大于0可以点击");
}
else
{
NSLog(@"内容为空不可点击");
}
}
@end
🌹输入框中有无内容时Button的颜色变化🌹
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...