• UISegmetControl


    一、UISegmentControl是一个分段控件,父类是UIControl,内涵数个button,并且都有对应下标index;

     

        NSArray *titles = @[@"护卫队",@"三军仪仗队",@"步兵方队",@"炮兵方队"];

        

        UISegmentedControl  *SegmentedC = [[UISegmentedControl alloc]initWithItems:titles];

        SegmentedC.frame = CGRectMake(20, 40, 335, 40);

        SegmentedC.backgroundColor = [UIColor whiteColor];

        

        //    设置文字颜色

        SegmentedC.tintColor = [UIColor redColor];

        //    [SegmentedC setTintColor:[UIColor whiteColor]];

        

        //    默认选中项

        SegmentedC.selectedSegmentIndex =0;

        

        

        //    修改某项的title

        [SegmentedC setTitle:@"女兵方阵" forSegmentAtIndex:2];

        

        //    指定某项宽度

        [SegmentedC setWidth:100 forSegmentAtIndex:1];

        

        //    设置title  文字大小   颜色

        

        NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:[UIColor blueColor]};

        NSDictionary *dic1 = @{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:[UIColor yellowColor]};

        

        [SegmentedC setTitleTextAttributes:dic forState:UIControlStateNormal];

        [SegmentedC setTitleTextAttributes:dic1 forState:UIControlStateSelected];

        

        //    添加点击事件

        [SegmentedC addTarget:self action:@selector(handleSegmented:) forControlEvents:UIControlEventValueChanged];

        

        

        

        [self.view addSubview:SegmentedC];

        

        

        [SegmentedC release];

  • 相关阅读:
    高德地图API,获取和设置zoom级别和中心点
    高德地图API注册使用教程简答演示
    HTML5 视频流行插件之video.js
    audio实现自定义音频播放器
    HTML5 audio API事件
    HTML5之audio属性
    GitLab的安装及使用教程
    设计模式六大原则(PHP)
    面向对象设计
    自定义的异常类
  • 原文地址:https://www.cnblogs.com/tig666666/p/4802063.html
Copyright © 2020-2023  润新知