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;

        }

    }

     
  • 相关阅读:
    【开源】我和 JAP(JA Plus) 的故事
    justauth-spring-boot-starter V1.3.5 发布成功
    JustAuth 1.15.9 版发布,支持飞书、喜马拉雅、企业微信网页登录
    详细介绍如何自研一款"博客搬家"功能
    推荐一款自研的Java版开源博客系统OneBlog
    JavaScript常用方法
    Markdown 语法学习
    Sublime Text常用设置之个人配置
    webStorm常用设置之过滤文件夹
    HTTP详解
  • 原文地址:https://www.cnblogs.com/PSSSCode/p/5508432.html
Copyright © 2011-2022 走看看