iOS-UIAlertController、UIActionSheet 、UITextView 、UIProgressView 、UIActivityIndicatorView UISegmentedControl 、UIStepper

pragma mark - 警告视图

IOS9 :

UIAlertController *ac = [UIAlertController alertControllerWithTitle:@"Funny Life" message:@"Network Error" preferredStyle:UIAlertControllerStyleAlert];

        [ac addAction:[UIAlertAction actionWithTitle:@"关闭" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {


        }]];


[self presentViewController:ac animated:YES completion:nil];

IOS9以前:

-(void)testAlertView

{

    //可以输入用户名和密码的输入

    UIAlertView *alertView = [[UIAlertView alloc] init];

    alertView.title = @"输入用户名和密码";

    alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;

    [alertView addButtonWithTitle:@"取消"];

    [alertView addButtonWithTitle:@"完成"];

    [alertView show];

    

    // UIAlertViewDelegate

    alertView.delegate = self;

}



- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;

{

    UITextField *nameText = [alertView textFieldAtIndex:0];

    UITextField *passwordText = [alertView textFieldAtIndex:1];

    

    NSLog(@"name:%@ pass:%@",nameText.text,passwordText.text);

}

pragma mark - 动作列表/操作列表

-(void)testActionSheet

{

    //实例: 实现一个分享的实例

    //  点击分享===>弹出动作列表显示===>分享

    

    UIButton *shareButton = [UIButton systemButtonWithFrame:CGRectMake(100, 100, 100, 30) title:@"分享" target:self action:@selector(shareButtonClick)];

    [self.view addSubview:shareButton];

}

-(void)shareButtonClick

{

    //创建一个动作列表视图

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"分享" delegate:self cancelButtonTitle:@"不分享了呢!" destructiveButtonTitle:nil otherButtonTitles:@"新浪微博",@"微信",@"微信圈子",@"邮件",@"短信",nil];

    

    //注意: 不要这样显示

    //[self.view addSubview:actionSheet];

    [actionSheet showInView:self.view];

}



- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;

{

    NSLog(@"buttonIndex = %d",buttonIndex);

}

pragma mark - 文本视图控件

-(void)testTextView

{

    //创建控件

    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(10, 30, 300, 400)];

    //推荐小说: 奇幻小说

    //  历史的尘埃(在历史的天空下, 所有人只不过是一粒尘埃)

    //  玄幻小说: 杨戬--人生长恨水长东

    //  西方骑士小说: 基督山伯爵

    //  言情小说: 几度深爱成秋凉

    //  都市(古典仙侠): 人欲

    //  股票: 鬼股

    

    //仙四主题: 我命由我不由天

    

    //注意: 点击return并不会回收键盘, 是换行

    //      要向回收, 自己添加按钮实现

    textView.text = @"尽人事, 听天命? 非也非也, 我命由我不由天, 尽人事, 听天命? 非也非也, 我命由我不由天, 尽人事, 听天命? 非也非也, 我命由我不由天, 尽人事, 听天命? 非也非也, 我命由我不由天, 尽人事, 听天命? 非也非也, 我命由我不由天, 尽人事, 听天命? 非也非也, 我命由我不由天, ";

    textView.backgroundColor = [UIColor orangeColor];

    textView.tag = 200;

    

    [self.view addSubview:textView];

    

    

    //要想回收键盘

    //  1.导航栏上添加完成按钮回收

    //  2.虚拟键盘的附件区域添加完成按钮

    //  3.添加一个根虚拟键盘联动的按钮

    

    UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];

    UIBarButtonItem *finishItem = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(dealTextBtnClick:)];

    finishItem.tag = 100;

    UIBarButtonItem *clearItem = [[UIBarButtonItem alloc] initWithTitle:@"清空" style:UIBarButtonItemStylePlain target:self action:@selector(dealTextBtnClick:)];

    clearItem.tag = 101;

    toolBar.items = @[finishItem,clearItem];

    textView.inputAccessoryView = toolBar;

}

-(void)dealTextBtnClick:(UIBarButtonItem *)item

{

    UITextView *textView = (UITextView *)[self.view viewWithTag:200];

    if(item.tag == 100)

    {

        [textView resignFirstResponder];

    }

    else if(item.tag == 101)

    {

        textView.text = @"";

    }

}

pragma mark - 进度条控件

-(void)testProgressView

{

    //创建进度条控件

    UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];

    progressView.frame = CGRectMake(100, 100, 200, 30);

    [self.view addSubview:progressView];

    

    //属性

    progressView.progress = .00;

    

    //模拟下载和下载完成的过程的过程

    [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(downloadProgress:) userInfo:progressView repeats:YES];

}



-(void)downloadProgress:(NSTimer *)timer

{

    

    UIProgressView *progressView = (UIProgressView *)timer.userInfo;

    progressView.progress += 0.02;

    if(progressView.progress >= 1.00)

    {

        //停止定时器

        [timer invalidate];

        

        UIAlertView *alertView = [[UIAlertView alloc] init];

        alertView.message = @"您的电影下载完成";

        [alertView addButtonWithTitle:@"确定"];

        [alertView show];

    }

}

pragma mark - 计数器/步进器控件

-(void)testStepper

{

    //创建计数器/步进器控件

    //注意: 宽度和高度固定的

    UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(200, 100, 0, 0)];

    [self.view addSubview:stepper];

    

    //属性设置

    //实例: 购物界面天添加输入商品的计数器

    stepper.minimumValue = 1;

    stepper.maximumValue = 10000000;

    stepper.value = 2;

    stepper.stepValue = 10;

    

    [stepper addTarget:self action:@selector(dealStepper:) forControlEvents:UIControlEventValueChanged];

    

    

    //

    UITextField *textFiled = [[UITextField alloc] initWithFrame:CGRectMake(10, 100, 180, 30)];

    textFiled.borderStyle = UITextBorderStyleRoundedRect;

    textFiled.text = @"2";

    textFiled.tag = 100;

    [self.view addSubview:textFiled];

    //注意回收键盘

    textFiled.delegate = self;

}



-(void)dealStepper:(UIStepper *)stepper

{

    UITextField *textFiled = (UITextField *)[self.view viewWithTag:100];

    // stepper.value

    textFiled.text = [NSString stringWithFormat:@"%d",(int)stepper.value];

}





-(BOOL)textFieldShouldReturn:(UITextField *)textField

{

    [textField resignFirstResponder];

    return YES;

}

pragma mark - 分段选择控件

-(void)testSegmentedControl

{

    //创建分段选择控件

    UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"小乔",@"流水",@"人家",@"老叔",@"昏鸦"]];

    segmentedControl.frame = CGRectMake(10, 100, 300, 30);

    [self.view addSubview:segmentedControl];

    

    //设置选择项

    segmentedControl.selectedSegmentIndex = 0;

    [segmentedControl insertSegmentWithTitle:@"手麻" atIndex:3 animated:YES];

    

    //事件处理

    [segmentedControl addTarget:self action:@selector(dealSegmentedControl:) forControlEvents:UIControlEventValueChanged];

    

}



-(void)dealSegmentedControl:(UISegmentedControl *)segmentedControl

{

    //获取选择项的序号

    NSLog(@"index = %d",segmentedControl.selectedSegmentIndex);

}



#pragma mark - 滑块控件

-(void)testSlider

{

    //创建滑块控件

    //注意: 修改长度, 高度是固定的 34

    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(100, 100, 200, 0)];

    //NSLog(@"s = %@",slider);

    [self.view addSubview:slider];

    

    //设置属性

    slider.minimumValue = 0;

    slider.maximumValue = 100;

    slider.value = 50;

    slider.tintColor = [UIColor redColor];

    

    //事件处理

    //注意: 事件类型

    [slider addTarget:self action:@selector(dealSlider:) forControlEvents:UIControlEventValueChanged];

}



-(void)dealSlider:(UISlider *)slider

{

    //获取当前值

    NSLog(@"slider.value = %f",slider.value);

}

pragma mark - 活动提示控件

-(void)testActivityIndicatorView

{

    //创建活动提示控件

    UIActivityIndicatorView *aiv = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

    aiv.center = CGPointMake(160, 240);

    [self.view addSubview:aiv];

    

    [aiv startAnimating];

    

    //模拟数据下载完成的操作

    [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(stopActivityIndicatorView:) userInfo:aiv repeats:NO];

}



-(void)stopActivityIndicatorView:(NSTimer *)timer

{

    UIActivityIndicatorView *aiv = timer.userInfo;

    [aiv stopAnimating];

}

pragma mark - 开关控件

-(void)testSwitch

{

    //创建UISwitch

    //细节: 大小是固定的 51X31

    UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(100, 100, 0, 0)];

    NSLog(@"%f %f",mySwitch.frame.size.width,

          mySwitch.frame.size.height);

    [self.view addSubview:mySwitch];

    

    //简单设置

    //设置状态

    mySwitch.on = YES;

    mySwitch.onTintColor = [UIColor redColor];

    mySwitch.tintColor = [UIColor blueColor];

    mySwitch.thumbTintColor = [UIColor yellowColor];





    

    //事件处理

    //注意: 事件类型 UIControlEventValueChanged

    [mySwitch addTarget:self action:@selector(dealSwitch:) forControlEvents:UIControlEventValueChanged];


}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容