UIControl

作者: 青花_ | 来源:发表于2016-02-21 20:13 被阅读0次

    UIControl 控制类

    主要学习了分段控制器、滑块控制器、页码控制器、开关、步进控制器

    一、分段控制器UISegmentedControl

    UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"消息", @"电话", @"微信"]];

    seg.frame = CGRectMake(100, 100, 200, 40);

    [self.view addSubview:seg];

    [seg release];

    选中分段下标

    seg.selectedSegmentIndex = 0;

     背景颜色

     seg.backgroundColor = [UIColor blackColor];

     渲染颜色

    seg.tintColor = [UIColor lightGrayColor];

      seg.layer.cornerRadius = 5;

      seg.clipsToBounds = YES;

    插入新的分段

      [seg insertSegmentWithTitle:@"陌陌" atIndex:2 animated:YES];

     添加响应事件(通过下标值的变化触发方法)

    [seg addTarget:self action:@selector(segAction:) forControlEvents:UIControlEventValueChanged];

    二、滑块控制器UISlider

    UISlider *sl = [[UISlider alloc] initWithFrame:CGRectMake(50, 50, 200, 50)];

    sl.backgroundColor = [UIColor yellowColor];

    [self.view addSubview:sl];

    [sl release];

     颜色设置

    划过距离的颜色(滑块左)

    sl.minimumTrackTintColor = [UIColor blackColor];

     未划过距离的颜色(滑块右)

    sl.maximumTrackTintColor = [UIColor redColor];

     滑块颜色

    sl.thumbTintColor = [UIColor greenColor];

    添加响应事件

    [sl addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];

     滑动范围

    最小值

    sl.minimumValue = -100;

    最大值

    sl.maximumValue = 1000;

    更新滑块起始点

    sl.value = -100;

    三、页码控制器

    UIPageControl *pc = [[UIPageControl alloc] initWithFrame:CGRectMake(50, 150, 100, 50)];

    pc.backgroundColor = [UIColor orangeColor];

    [self.view addSubview:pc];

    [pc release];

    页数

    pc.numberOfPages = 4;

    当前页

    pc.currentPage = 3;

     颜色

    页码颜色

    pc.pageIndicatorTintColor = [UIColor redColor];

     当前页颜色

    pc.currentPageIndicatorTintColor = [UIColor greenColor];

     响应事件

    [pc addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventValueChanged];

    四、UISwitch开关

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

    sw.backgroundColor = [UIColor whiteColor];

    [self.view addSubview:sw];

    [sw release];

     开关属性

    sw.on = YES;

     开启时颜色

    sw.onTintColor = [UIColor redColor];

    关闭时边框颜色

    sw.tintColor = [UIColor blackColor];

    按钮颜色

    sw.thumbTintColor = [UIColor blackColor];

    响应方法

    [sw addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];

    五、步进控制器stepper

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

    stepper.backgroundColor = [UIColor cyanColor];

    [self.view addSubview:stepper];

    最小值

    stepper.minimumValue = 0;

    最大值

    stepper.maximumValue = 20;

     value 控制初值

    stepper.value = 1;

     stepValue每次变化的大小

    stepper.stepValue = 4;

     是否显示每次值变化

    stepper.continuous = YES;

     按住时 是否自动变化

    stepper.autorepeat = YES;

     是否允许从max回到min

    stepper.wraps = YES;

    添加事件

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

    相关文章

      网友评论

          本文标题:UIControl

          本文链接:https://www.haomeiwen.com/subject/kwvmkttx.html