• 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];
        
    }

    效果图如下:

  • 相关阅读:
    用mysql+redis实现微博feed架构上需要注意哪些问题
    windows7下安装zend studio5.5
    鼠标移出DIV层时,触发onMouseOut事件
    关于MVVM和RAC的一些拓展阅读
    Swift(上) 常量, 变量, 数据类型, 循环, 选择结构 简单函数
    SDWebImage的使用
    App Store新应用提审攻略
    关于iOS的推送服务的点点
    iOS开发代码规范
    伟大的RAC和MVVM入门(二)
  • 原文地址:https://www.cnblogs.com/lyz0925/p/6101104.html
Copyright © 2020-2023  润新知