UILable是今天回忆的第一节,之前所学的都忘得差不多了,我远远没想到一个标签也有很多很多的含义
//UILable
UILabel *label = [[UILabel alloc]init];//初始化文本标签
label.frame = CGRectMake(20.0, 20.0, 120, 80);//设置大小
label.backgroundColor = [UIColor blackColor];//设置背景为黑色
label.text = @"你好";
label.textColor = [UIColor whiteColor];//设置文字颜色
label.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:label];//添加到视图
按钮是回忆的第二节,一个Button想要完全的显示需要二十到三十行代码
//UIButton
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];//[[UIButton alloc]init];//初始化按钮标签
// UIButton *button1 = [[UIButton alloc]init];//初始化按钮标签
button.frame = CGRectMake(20.0, 20.0, 120, 80);//设置大小
button.backgroundColor = [UIColor blackColor];//设置背景为黑色
[button setTitle:@"你好" forState:UIControlStateNormal];
//按钮添加点击事件
[button addTarget:self action:@selector(clickButton) forControlEvents:UIControlEventTouchDown];
[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchDown];
//按钮 状态 ,设置图片
// label.text = @"你好";
// label.textColor = [UIColor whiteColor];//设置文字颜色
// label.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:button];//添加到视图
而我敲到这的时候,我便开始在想,如何的使它看起来更加的像一个真正的按钮,接下来便开始利用起了if语句也就是我们常说的如果,想起在刚学C语言的时候‘如果语句’有很多种,直到今天真正利用的也就一个if了
-(void)click:(UIButton*) btn{
// btn.selected = YES;
NSLog(@"你好");
if([btn.titleLabel.textisEqualToString:@"Hello"]) {
[btnsetTitle:@"你好" forState:UIControlStateNormal];
}else{
[btnsetTitle:@"Hello" forState:UIControlStateNormal];
}
/*
if ([btn.titleLabel.text isEqualToString:@"Hello"]) {
[btn setTitle:@"你好" forState:UIControlStateNormal];
}else{
[btn setTitle:@"Hello" forState:UIControlStateSelected];
}
*/
}