zoukankan      html  css  js  c++  java
  • UISegmentedControl 的使用

    /** 设置选择器 */
    - (void)setUpSegmentCtr {
        UISegmentedControl *segmentCtr = [[UISegmentedControl alloc] initWithItems:@[@"采购订单",@"销售订单"]];
        self.navigationItem.titleView = segmentCtr;
        [segmentCtr addTarget:self action:@selector(didClicksegmentedControlAction:) forControlEvents:UIControlEventValueChanged];
        self.segmentCtr = segmentCtr;
        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:EMCNavColor,
                             NSForegroundColorAttributeName,
                             [UIFont boldSystemFontOfSize:14],
                             NSFontAttributeName,nil];
        
        [ self.segmentCtr setTitleTextAttributes:dic forState:UIControlStateSelected];
        
        NSDictionary* unselectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:14],
                                                   NSForegroundColorAttributeName: [UIColor whiteColor]};
        [self.segmentCtr setTitleTextAttributes:unselectedTextAttributes forState:UIControlStateNormal];
        
        [self.segmentCtr setBackgroundImage:[UIImage imageWithColor:[UIColor clearColor]] forState:UIControlStateNormal barMetrics:UIBarMetricsDefaultPrompt];
        [self.segmentCtr setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor]] forState:UIControlStateSelected barMetrics:UIBarMetricsDefaultPrompt];
        
         self.segmentCtr.tintColor = [UIColor whiteColor];
         self.segmentCtr.apportionsSegmentWidthsByContent = NO;
        self.segmentCtr.backgroundColor = [UIColor clearColor];
        self.segmentCtr.selectedSegmentIndex = 0;
    }

    再viewdidload中添加

    - (void)viewDidLoad {
        [super viewDidLoad];
        
        /** 设置选择器 */
        [self setUpSegmentCtr];
        
    }

    效果图如下:

  • 相关阅读:
    2.2 Scala基础知识
    Linux---用户及权限管理类命令
    Linux---进程控制类命令
    Linux---vim编辑文本文件
    Linux---文件压缩与解压缩命令
    Linux---查找命令
    Linux---基本目录与文件命令
    nginx配置技巧汇总
    Go 内嵌静态资源
    go语言的time.Sleep
  • 原文地址:https://www.cnblogs.com/lyz0925/p/6101104.html
Copyright © 2011-2022 走看看