zoukankan      html  css  js  c++  java
  • iOS-UISegmentedControl-隐藏边框

    原理: 

    1. 用tintColor属性,把整个UISEgmentControl 设置成为透明色.

    2. 设置正常状态下的titleTextAttributes.和选中状态下的titleTextAttributes.

    #import "SecondViewController.h"
    #import "Masonry.h"
    
    @interface SecondViewController ()
    
    @property (nonatomic, strong) UISegmentedControl * segmentedControl_one;
    
    @end
    
    @implementation SecondViewController
    
    #pragma mark - 生命周期
    #pragma mark viewDidLoad
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        [self basicSetting];
        
        [self addSegmentedControl_one];
        
    }
    
    #pragma mark - 系统代理
    
    #pragma mark - 点击事件
    - (void)segmentedControl_one:(UISegmentedControl *)sender
    {
        NSLog(@"index: %ld",(long)sender.selectedSegmentIndex);
        
    }
    
    #pragma mark - 实现方法
    #pragma mark 基本设置
    - (void)basicSetting
    {
        self.title = @"隐藏边框";
    }
    
    - (void)addSegmentedControl_one
    {
        [self.view addSubview:self.segmentedControl_one];
        [self.segmentedControl_one mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.mas_equalTo(self.view).with.offset(10);
            make.right.mas_equalTo(self.view).with.offset(-10);
            make.top.mas_equalTo(self.view).with.offset(30);
            make.height.mas_equalTo(40);
        }];
    }
    
    
    #pragma mark - setter & getter
    - (UISegmentedControl *)segmentedControl_one
    {
        if (!_segmentedControl_one)
        {
            NSArray * array = @[@"第一段",@"第二段",@"第三段",@"第四段"];
            self.segmentedControl_one = [[UISegmentedControl alloc] initWithItems:array];
            
            // 去掉颜色,现在整个segment偶看不到,可以相应点击事件
            self.segmentedControl_one.tintColor = [UIColor clearColor];
            
            // 正常状态下
            NSDictionary * normalTextAttributes = @{NSFontAttributeName : [UIFont systemFontOfSize:16.0f],NSForegroundColorAttributeName : [UIColor grayColor]};
            [self.segmentedControl_one setTitleTextAttributes:normalTextAttributes forState:UIControlStateNormal];
            
            // 选中状态下
            NSDictionary * selctedTextAttributes = @{NSFontAttributeName : [UIFont boldSystemFontOfSize:20.0f],NSForegroundColorAttributeName : [UIColor redColor]};
            [self.segmentedControl_one setTitleTextAttributes:selctedTextAttributes forState:UIControlStateSelected];
            
            
            [self.segmentedControl_one addTarget:self action:@selector(segmentedControl_one:) forControlEvents:UIControlEventValueChanged];
        }
        return _segmentedControl_one;
    }
    
    @end
  • 相关阅读:
    【转载】apache kafka系列之-监控指标
    自动恢复被挂掉的hbase region server
    beeline连接hive server遭遇MapRedTask (state=08S01,code=1)错误
    sqoop-1.4.6安装配置
    spark RDD的元素顺序(ordering)测试
    【转载】常用Maven插件介绍
    【转载】Spark SQL 1.3.0 DataFrame介绍、使用
    SparkSQL之数据源
    spark集成hive遭遇mysql check失败的问题
    hive启动报错: Found class jline.Terminal, but interface was expected
  • 原文地址:https://www.cnblogs.com/mancong/p/5595506.html
Copyright © 2011-2022 走看看