zoukankan      html  css  js  c++  java
  • UISegmentedControl-iOS

    //建立UISegmentedControl的数组

    NSArray *segmentedArray = [NSArray arrayWithObjects:@"线下培训",@"在线培训",@"模拟面试",@"Marlin面试",nil];

     

    UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:segmentedArray];

    //设置样式 当为BorderedBartintColor才有效

    segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;

    segmentedControl.tintColor = [UIColor clearColor];

    //    文字选中的颜色

        [segmentedControl setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:39/255.0 green:193/255.0 blue:180/255.0 alpha:1.0f]} forState:UIControlStateSelected];

    //   文字未选中的颜色

        [segmentedControl setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateNormal];

        //背景未选中的颜色

        [segmentedControl setBackgroundImage:[WTImage imageWithColor:[UIColor colorWithRed:39/255.0 green:193/255.0 blue:180/255.0 alpha:1.0f] size:CGSizeMake(WIDTH, 44) alpha:1] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

        //背景选中的颜色

        [segmentedControl setBackgroundImage:[WTImage imageWithColor:[UIColor whiteColor] size:CGSizeMake(WIDTH, 44) alpha:1] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];

        //设置圆角

        segmentedControl.layer.cornerRadius = 4;

        

        segmentedControl.clipsToBounds = YES;

    //设置frame

      segmentedControl.frame = CGRectMake(0.0, 0.0, 290, 30.0);

    //设置默认选中的index

        segmentedControl.selectedSegmentIndex = 0;

    [segmentedControl addTarget:self  action:@selector(indexDidChangeForSegmentedControl:)

                   forControlEvents:UIControlEventValueChanged];

        //方法1

        //[self.navigationController.navigationBar.topItem setTitleView:segmentedControl];

        //方法2

        [self.navigationItem setTitleView:segmentedControl];

    //segmentedControl选中方法

    -(void)indexDidChangeForSegmentedControl:(UISegmentedControl *)Seg{

        

        NSInteger Index = Seg.selectedSegmentIndex;

        NSLog(@"Index %i", Index);

        switch (Index) {

            case 0:            

                [self selectmyView1];

                

                NSLog(@"%li",(long)Index);

                break;

            case 1:            

                [self selectmyView2];

                NSLog(@"%li",(long)Index);

                break;

            case 2:

                [self selectmyView3];

                NSLog(@"%li",(long)Index);

                break;

            case 3:            

                [self selectmyView4];

                NSLog(@"%li",(long)Index);

                break;

            default:

                break;

        

        }

     

    }

  • 相关阅读:
    vue 项目界面绘制_stylus_iconfont_swiper
    react_结合 redux
    BOM 浏览器对象模型_当前窗口的浏览历史 history 对象
    BOM 浏览器对象模型_Storage 接口
    react_app 项目开发 (9)_数据可视化 ECharts
    react_app 项目开发 (8)_角色管理_用户管理----权限管理 ---- shouldComponentUpdate
    BOM 浏览器对象模型_同源限制
    面试题: 多个 await 处理,有一个失败,就算作失败
    react_app 项目开发 (7)_难点集合
    react_app 项目开发_遇到的坑
  • 原文地址:https://www.cnblogs.com/ansyxpf/p/7197394.html
Copyright © 2011-2022 走看看