1,UISwitch,该控件,选择器
代码:
//初始化对象,UISwitch默认固定大小,宽49,高31
UISwitch *sw = [[UISwitch alloc]init];
//设置子控件和父控件的中心点相同
sw.center = self.view.center;
//设置选中时的颜色
sw.onTintColor = [UIColor redColor];
//设置圆点颜色
sw.thumbTintColor = [UIColor blueColor];
//添加点击事件 UIControlEventValueChanged |UIControlEventTouchUpInside
[sw addTarget:self action:@selector(swClick:) forControlEvents:UIControlEventValueChanged];
//添加到父控件
[self.view addSubview:sw];
方法:
#pragma mark - 选择器UISwitch的响应方法
-(void)swClick:(UISwitch *)sw {
//检查一下sw的状态
NSLog(@"%d",sw.isOn);
}
2,文本及相应知识点:
/*
文本 UILable
输入文本、输入文本框 UITextFiled \ UITextView
单行输入文本框 UITextFiled
多行输入文本框 UITextView
*/
//初始化文本对象
UILabel *lable = [[UILabel alloc]init];
//设置在父控件的位置
lable.frame = CGRectMake(20.0, 20.0, 100.0, 80.0);
//设置文本内容
lable.text = @"我是个文本,可以设置多行显示。";
//设置背景颜色
lable.backgroundColor = [UIColor yellowColor];
//设置多行显示,当高度不够的时候,会显示不全
lable.numberOfLines = 2;
//添加到主视图
[self.view addSubview:lable];
3,UIAlterView 弹窗的简单了解:
1)初始化和弹窗弹出,设置代理
/*
UIAlertView
提示框
*/
//初始化对象
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"UIAlertView提示" message:@"显示提示信息" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",@"我想一下", nil];
//调用显示方法
[alert show];
2)在接口位置遵循代理(UIAlertViewDelegate):
@interface ViewController ()<UIAlertViewDelegate>//1,在接口位置遵循协议
@end
3)实现(UIAlertViewDelegate)代理方法:
#pragma mark - UIAlertViewDelegate
//相应按钮点击事件
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"buttonIndex:%ld",buttonIndex);
switch (buttonIndex) {
case 0:
//响应了取消按钮
break;
case 1:
//响应了确定按钮
break;
case 2:
//响应了“我想一下”按钮
break;
default:
break;
}
}
网友评论