zoukankan      html  css  js  c++  java
  • 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];

        }

    }

  • 相关阅读:
    企业使用数据库的12种姿势
    回归架构本质,重新理解微服务
    Java中随机数的产生方式与原理
    自动类型转换、强制类型转换、作用域、整型表数范围
    创建自定义类的对象数组
    CentOS上安装比较习惯的代码编辑器
    ubuntu 15.04 的安装遇到的问题及其解决方法
    算法思想篇(1)————枚举算法
    初来乍到
    Eclipse中获取html jsp 标签的属性提示信息方法
  • 原文地址:https://www.cnblogs.com/tanglie/p/6492468.html
Copyright © 2011-2022 走看看