zoukankan      html  css  js  c++  java
  • iOS

    1、UISegmentedControl    

        NSArray * array = @[@"red",@"green",@"yellow",@"blue",@"orange"];    

        //分段选择器

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

        segment.frame = CGRectMake(20, CGRectGetHeight(self.view.frame) - 100, CGRectGetWidth(self.view.frame) - 40, 30);

        //是否能选中

        segment.momentary = NO;

        //文字适应宽度

        segment.apportionsSegmentWidthsByContent = NO;

        //根据索引插入数据

        //    [segment insertSegmentWithTitle:@"apple" atIndex:1 animated:YES];

        //    [segment setImage:[UIImage imageNamed:@"onimage"] forSegmentAtIndex:2];

        segment.tintColor = [UIColor orangeColor];

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

        [self.view addSubview:segment];   

    }

    - (void)segmentAction:(UISegmentedControl *)segment {

        NSInteger index = segment.selectedSegmentIndex;

        switch (index) {

            case 0:

                self.view.backgroundColor = [UIColor redColor];

                break;

            case 1:

                self.view.backgroundColor = [UIColor greenColor];

                break;

            case 2:

                self.view.backgroundColor = [UIColor yellowColor];

                break;

            case 3:

                self.view.backgroundColor = [UIColor blueColor];

                break;

            case 4:

                self.view.backgroundColor = [UIColor orangeColor];

                break;

            default:

                break;

        }

    }

     
  • 相关阅读:
    CentOS6.5配置MySQL主从同步
    CentOS6.5安装telnet
    linux 下安装Google Chrome (ubuntu 12.04)
    jdk w7环境变量配置
    JDBCConnectionException: could not execute query,数据库连接池问题
    注意开发软件的版本问题!
    linux mysql命令行导入导出.sql文件 (ubuntu 12.04)
    linux 下root用户和user用户的相互切换 (ubuntu 12.04)
    linux 下 vim 的使用 (ubuntu 12.04)
    linux 下安装配置tomcat-7 (ubuntu 12.04)
  • 原文地址:https://www.cnblogs.com/PSSSCode/p/5508432.html
Copyright © 2011-2022 走看看