您的位置:首页 > 产品设计 > UI/UE

OC-UIAlertController& UIStepper& UISlider& UISwitch

2016-09-02 20:21 513 查看

UIAlertController

警告框(AlertView 位于屏幕中间)

1.创建UIAlertController的实例,创建实例时需要制定一个style参数,将该参数写成Alert样式,则代表创建的是警告框

2.创建界面上的按键

3.将创建好的按键添加到警告框中

4.为AlertController添加文本框 (可选)

5将警告呈现出来

操作表 (ActionSheet)

1.创建UIAlertController的实例,创建实例时需要制定一个style参数,将该参数写成ActionSheet样式,则代表创建的是警告框

2.创建界面上的按键

3.将创建好的按键添加到操作表中

4.将警告呈现出来

//1.创建UIAlertController的实例,创建实例时需要制定一个style参数,将该参数写成Alert样式,则代表创建的是警告框
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"用户名或密码错误" preferredStyle:UIAlertControllerStyleAlert];
//2.创建界面上的按键
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];

UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"重新登录" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
NSLog(@"重新登录按键 按下");
//获取 文本框中输入的 内容
NSString *username = alert.textFields[0].text;
NSString *password = alert.textFields[1].text;
NSLog(@"输入的用户名是 %@  密码是 %@",username,password);
}];

UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"删除应用" style:UIAlertActionStyleDestructive handler:nil];

//3.将创建好的按键添加到警告框中
[alert addAction:action2];
[alert addAction:action1];
[alert addAction:action3];

//4.为AlertController添加文本框
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
//参数 textField 就是我们添加的文本框实例,我们可以通过该参数对 添加的文本框的属性进行修改
textField.placeholder = @"请重新输入用户名";
}];
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"请重新输入密码";
}];

//5将警告呈现出来
[self presentViewController:alert animated:YES completion:nil];


UIStepper 步进控件

作用:记录一个浮点数值,并且控件提供了两个按钮界面,由用户精确的控制记录的这个值的递增或递减

核心属性:value

核心事件:valueChanged

- (IBAction)valueChanged:(UIStepper *)sender {
self.label.text = [NSString stringWithFormat:@"%.2f",sender.value];
}


UISlider 滑块控件

作用: 记录一个浮点数值,通过一个可滑动的按钮,快速的在某个范围内容得到一个不容精确控制的数值

核心属性:value

核心事件:valueChanged

- (IBAction)valueChanged:(UISlider *)sender {
self.label.text = [NSString stringWithFormat:@"%.2f",sender.value];
[self setupMyViewBackgroundColor];
}


UISwitch开关控件

作用:记录一个布尔值,通过点击的方式,可以记录用户的是或否的选择

核心属性: on

核心事件:valueChanged

- (IBAction)valueChanged:(UISwitch *)sender {
self.button.enabled = sender.on;
}

- (IBAction)switchButtonClick:(id)sender {
//    self.mySwitch.on = !self.mySwitch.on;
[self.mySwitch setOn:!self.mySwitch.on animated:YES];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐