#pragma mark----UILabel(显示文本内容的控件)---------------------------------
// UILabel文本控件 用来显示文本内容的控件
CGFloat sWidth =CGRectGetWidth([UIScreen mainScreen].bounds);
label = [[UILabel alloc]initWithFrame:CGRectMake(10, 50, sWidth-10*2, 40)];//控件初始化
label.backgroundColor = [UIColor blackColor];//设置label背景的颜色
label.text = @"老师,下一步怎么办?";//向label导入文字
label.font = [UIFont systemFontOfSize:30];//设置字体的大小
label.adjustsFontSizeToFitWidth = YES;//自动设置字体的宽度 根据label的宽度 来达到显示全部内容
//在ios7.1之前 默认是有边框的(白色)现在默认是透明的
label.textColor = [UIColor redColor];// 更改字体的颜色
label.shadowColor = [UIColor greenColor];// 设置阴影颜色
label.shadowOffset = CGSizeMake(-10, 5);// 设置偏移量:第一个参数负责左右(宽) 第二个参数负责上下(高)
label.textAlignment = NSTextAlignmentCenter;// 设置居中 向左向右
label.numberOfLines = 100;//设置行
[self.view addSubview:label];
#pragma mark----UIButton(按钮控件)----------------------------------------
// UIButton 按钮控件 点击按钮 会触发某个事件
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(120, 400, 100, 40);//设置按钮坐标原点(CGFloat x,CGFloat y)和(CGFloat width,CGFloat height)
[button addTarget:self action:@selector(changeTitle:) forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor = [UIColor whiteColor];//设置按钮背景颜色
button.selected = NO;//判断按钮是否被选中
[button setTitle:@"按我" forState:UIControlStateNormal];//设置名字
[button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal ];//设置字体颜色
[button setTitle:@"按我" forState:UIControlStateHighlighted];//设置字体高亮
button.showsTouchWhenHighlighted = YES;//触发高亮状态
// 设置触发字体颜色
[button setBackgroundImage:[UIImage imageNamed:@"1.1.png" ] forState:UIControlStateNormal];//触发更改图片
[button setBackgroundImage:[UIImage imageNamed:@"2.2.png" ] forState:UIControlStateNormal];//触发更改图片
[button setBackgroundImage:[UIImage imageNamed:@"3.3.png" ] forState:UIControlStateNormal];//触发更改图片
[self.view addSubview:button];
}
//一个按钮只能触发一个方法
- (void)changeTitle:(UIButton *)sender
{
NSLog(@"%d",sender.selected);
if ((sender.selected = YES)) {
label.text = @"放学回家吃饭";
label.textColor = [UIColor purpleColor];
sender.selected = YES;
}else{
label.text = @"爱我中华";
label.textColor = [UIColor purpleColor];
sender.selected = NO;
}