/*************** 1.分段选取器 ********************/
//参数数组里存放的是字符串(标题)或者图片
UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:@[@"电视剧",@"电影",@"综艺",@"动漫"]];
segment.frame = CGRectMake(50, 100, screenBounds.size.width-100, 40);
//设置哪个分段处于选中状态
segment.selectedSegmentIndex = 0;
[segment addTarget:self action:@selector(segmentValueChange:) forControlEvents:UIControlEventValueChanged];
//设置内容渲染颜色
segment.tintColor = [UIColor redColor];
[self.view addSubview:segment];
/***************** 2.UISlider滑块*************/
UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(50, 200, screenBounds.size.width-100, 40)];
//设置最小值
slider.minimumValue = 1;
//设置最大值
slider.maximumValue = 10;
//设置当前显示的value
slider.value = 5;
//设置图片
slider.minimumValueImage = [UIImage imageNamed:@"1"];
slider.maximumValueImage = [UIImage imageNamed:@"2"];
[slider setThumbImage:[UIImage imageNamed:@"1"] forState:UIControlStateNormal];
//设置颜色
// slider.minimumTrackTintColor = [UIColor redColor];
// slider.maximumTrackTintColor = [UIColor blackColor];
// slider.thumbTintColor = [UIColor redColor];
[slider addTarget:self action:@selector(sliderValueChange:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:slider];
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backItem;
/********************3. UISwitch **************/
UISwitch *sw = [[UISwitch alloc] initWithFrame:CGRectMake(150, 100, 10, 10)];
//设置开启状态
sw.on = YES;
//设置相关颜色
sw.onTintColor = [UIColor redColor];
sw.thumbTintColor = [UIColor greenColor];
sw.tintColor = [UIColor blackColor];
//设置圆角半径
sw.backgroundColor = [UIColor yellowColor];
sw.layer.cornerRadius = 15;
sw.layer.masksToBounds = YES;
//添加事件
[sw addTarget:self action:@selector(swValueChange:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:sw];
/***4. UIActivityIndicatorView等待加载符 *****/
UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activity.center = self.view.center;
//让等待加载符 ,开始加载
// [activity startAnimating];
// activity.backgroundColor = [UIColor blackColor];
//停止加载
// [activity stopAnimating];
//设置颜色
activity.color = [UIColor blueColor];
activity.tag = 100;
[self.view addSubview:activity];
self.title = @"步进器和进度条";
/*********** 5.步进器 *************/
UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(100, 100, 1, 1)];
stepper.center = CGPointMake(screenBounds.size.width/2, 100);
//设置最小值
stepper.minimumValue = 0;
//设置最大值
stepper.maximumValue = 10;
//设置步长
stepper.stepValue = 1;
//添加事件
[stepper addTarget:self action:@selector(stepperValueChange:) forControlEvents:UIControlEventValueChanged];
//设置颜色
stepper.tintColor = [UIColor orangeColor];
[self.view addSubview:stepper];
/************ 6.进度条UIProgressView ********/
UIProgressView *progress = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
progress.frame = CGRectMake(50, 200, screenBounds.size.width-100, 9);
//当前进度条的进度,范围(0-1之间)
progress.progress = 0;
//设置颜色
progress.progressTintColor = [UIColor redColor];
progress.tag = 100;
progress.trackTintColor = [UIColor whiteColor];
[self.view addSubview:progress];
//********************** 7.创建警告框
// UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"⚠️" message:@"您确定要自杀吗?" delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"YES",@"考虑一下",@"让我想会儿", nil];
//
// [alertView show];//显示出来
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"信息" message:@"请输入用户名和密码" delegate:self cancelButtonTitle:@"返回" otherButtonTitles:@"确定", nil];
//设置警告框的样式
alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
[alertView show];
//************************ 8.操作列表对象
-(void)creatAlerView{
// UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"⚠️" message:@"您确定要自杀吗?" delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"YES",@"考虑一下",@"让我想会儿", nil];
//
// [alertView show];//显示出来
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"信息" message:@"请输入用户名和密码" delegate:self cancelButtonTitle:@"返回" otherButtonTitles:@"确定", nil];
//设置警告框的样式
alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
[alertView show];
}
iOS8.0之后的警告框和操作列表对象
-(void)creatAlerView{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"信息" message:@"请输入用户名和密码" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"返回" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
NSLog(@"返回按钮被点击了");
}];
UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//打印出输入的用户名和密码的信息
UITextField *field1 = [alert.textFields firstObject];
UITextField *field2 = alert.textFields[1];
NSLog(@"您输入的用户名是:%@ 密码是:%@",field1.text,field2.text);
}];
[alert addAction:action1];
[alert addAction:action2];
//为UIAlertController添加文本框
//可以向对话框添加任意数目的UITextField类型的对象,并且在Block语句里面使用所有的UITextField的属性
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"请输入用户名:";
textField.textColor = [UIColor redColor];
textField.font = [UIFont systemFontOfSize:20];
}];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"请输入密码:";
textField.secureTextEntry = YES;
textField.font = [UIFont systemFontOfSize:20];
}];
[self presentViewController:alert animated:YES completion:nil];
}
-(void)creatActionSheet{
UIAlertController *sheet = [UIAlertController alertControllerWithTitle:nil message:@"分享" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"微信分享" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
NSLog(@"微信分享");
}];
UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"QQ分享" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@"QQ分享");
}];
UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"微博分享" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@"微博分享");
}];
UIAlertAction *action4 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@"取消");
}];
[sheet addAction:action1];
[sheet addAction:action2];
[sheet addAction:action3];
[sheet addAction:action4];
[self presentViewController:sheet animated:YES completion:nil];
}