• ios 初体验< UISegmentedControl 分段控件>


     小知识:  数组快速创建 @[@"",@"",@"",@"".......],字典快速创建方法:@{@"",@"",@"",@""......} ,可变,和不可变,

    快速实例化一个 UISegmentedControl *segmentedContrl = [[UISegmentedControl alloc]initWithItems:@[@"红色",@"黄色",@"灰色"]];  //里面装的是个数组

     UISegmentedControl 继承自UIControl  添加点击事件

      设置其位置 通过获取 屏幕居中点 

     segmentedContrl.bounds = CGRectMake(0, 0, 250, 30);

        segmentedContrl.center = CGPointMake(self.view.center.x, self.view.center.y + 15);

        默认选中由于里面是个数组

        segmentedContrl.selectedSegmentIndex = 0 ;

        默认字体 从字典里面去取

        [segmentedContrl setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor orangeColor]} forState:UIControlStateNormal];

        添加事件

        [segmentedContrl addTarget:self action:@selector(controlProgress:) forControlEvents:UIControlEventValueChanged];

        [self.view addSubview:segmentedContrl];

     点击事件

    - (void)controlProgress:(UIView *)sender{

        //判断该对象是否是 switch

        if ([sender isKindOfClass:[UISwitch class]]) {

            强转 判断传进来是

            UISwitch *switchContol = (UISwitch *)sender;

            条件表达式 判断开关动画的显示

            switchContol.on ? [_indicatorView startAnimating]:[_indicatorView stopAnimating];

        }

        if ([sender isKindOfClass:[UISlider class]]) {

            强转

            UISlider *slider = (UISlider *)sender;

            self.view.alpha = slider.value;

        }

        if ([sender isKindOfClass:[UISegmentedControl class]]) {

            强转

            UISegmentedControl *segmentedContrl = (UISegmentedControl *)sender;

             把颜色存入一个数组

            NSArray *colorArry = @[[UIColor redColor],[UIColor yellowColor],[UIColor grayColor]];

            改变颜色

            self.view.backgroundColor = colorArry[segmentedContrl.selectedSegmentIndex];

        }

    }

  • 相关阅读:
    React学习 之 阶段性小作品(待办事项_已完成事项 CRUD)
    React 学习之 键盘事件 表单事件 事件对象以及React中的ref获取dom节点 、React实现类似Vue的双向数据绑定
    mysql 时间戳 今天 昨天 7天 30天 及未来时间
    mysql历史数据自动归档
    配置nginx支持跨域访问
    AWK 简明教程
    shell 生成指定范围随机数与随机字符串
    Linux下Shell的for循环语句
    系统部署安装工具 WinToHDD Enterprise v4.2
    格式工厂 FormatFactory v5.1.0.0
  • 原文地址:https://www.cnblogs.com/tanglie/p/6492468.html
Copyright © 2020-2023  润新知