UI第六天

控件大集合


UISegmentcontroller 增加删除事件

UISlider 在一条上拖动

UISwitch 开关

UIActivityIndicatorView 菊花

UIProgressView 进度条

UIStepper 步进器(+/- num)

UIAlertView 提示(中间弹出的)

UIActionSheet 提示(下面的)


一些实用方法:

设置背景随机颜色:

vc.view.backgroundColor = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1.0];



一些概念:

1.UISegmentedControl:

UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:array];


/是否能连续选中   YES为能连续选中 NO不能

   segment.momentary = YES;

  //添加点击事件

[segment addTarget:self action:@selector(pressSegment:) forControlEvents:UIControlEventValueChanged];


 - (void)pressSegment:(UISegmentedControl *)segment

{

    switch (segment.selectedSegmentIndex) {

        case 0:

        {


        }

            break;

        default:

            break;

    }

}


2.UISlider

UISlider * slider = [[UISlider alloc] initWithFrame:CGRectMake(40, 100, self.view.frame.size.width - 80, 20)];//高度设置没用

//按钮开始时所处位置

slider.value = 2.0;

//一条的最短

slider.minimumValue = 0.0;

//一条的长度

slider.maximumValue = 100.0;

//按钮左边的颜色

slider.minimumTrackTintColor = [UIColor redColor];

//按钮右边的颜色  

slider.maximumTrackTintColor = [UIColor yellowColor];

//按钮上的图标

[slider setThumbImage:[UIImage imageNamed:@"player2"] forState:UIControlStateNormal];



- (void)sliderValueChange

{

    UISlider *slider1 = (id)[self.view viewWithTag:100];

    float value  = slider1.value;

    value += 1;

    [slider1 setValue:value animated:YES];

    NSLog(@"%f",slider1.value);

    if (slider1.value == slider1.maximumValue)

    {

        [timer invalidate];//跑完后停止,使定时器无效

//        slider1.value = 0.0;//循环跑

    }

}


3.UISwitch

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


sw.on = YES;

    

sw.onTintColor = [UIColor blackColor];

    

sw.thumbTintColor = [UIColor whiteColor];


- (void)switchChange:(UISwitch *)sw

{

    if (sw.isOn)

    {

        NSLog(@"********开关即将开启");

    }

    else

    {

        NSLog(@"XXXXXXXX开关即将关闭");

    }

//    sw.on = !sw.on;

}


4.UIActivityIndicatorView


 /*

     UIActivityIndicatorViewStyleWhiteLarge,

     UIActivityIndicatorViewStyleWhite,

     UIActivityIndicatorViewStyleGray,

     */

    //设置菊花样式

    indicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;

//设置当动画停止的时候,是否隐藏菊花 YES为隐藏 默认 NO为不隐藏

indicatorView.hidden = NO;


[indicatorView startAnimating];


 //开启状态栏上的菊花

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];



- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

UIActivityIndicatorView *indicatorView = (id)[self.view viewWithTag:100];

    

[indicatorView stopAnimating];

//关闭状态栏上的菊花

[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];

}


5.UIProgressView


 //设置进度值 范围是0.0-1.0

progressView.progress = 0.1;

    [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(valueChange) userInfo:nil repeats:YES];


- (void)valueChange

{

    UIProgressView *progressView = (id)[self.view viewWithTag:100];

    float value = progressView.progress;

    value += 0.01;

    [progressView setProgress:value animated:YES];

}


6.UIStepper:


stepper.value = 100.0;

    

stepper.minimumValue = 0.0;

    

stepper.maximumValue = 120.0;

    

stepper.stepValue = 4.0;



- (void)valueChange:(UIStepper *)stepper

{

    UILabel *label = (id)[self.view viewWithTag:100];

    

    label.text = [NSString stringWithFormat:@"%f",stepper.value];

}


7.UIAlertView:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"miss" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",@"miss",@"XX", nil];

    

    alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;


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

{

    //获取输入框的内容

    UITextField *userT = [alertView textFieldAtIndex:0];

    UITextField *passT = [alertView textFieldAtIndex:1];


    switch (buttonIndex) {

        case 0:

        {

            

        }

            break;

        default:

            break;

    }

    NSLog(@"%ld",buttonIndex);

}


8.UIActionSheet

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"拍照" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"警告" otherButtonTitles:@"确定", @"xxx",nil];


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

{

    NSLog(@"%ld",buttonIndex);

}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值