UISegmentedControl 去掉中间的分割线


#pragma mark -- 顶部的切换按钮
- (void)createTopSegmentUI
{
    if (!_segmentView)
    {
        _segmentView = [[UISegmentedControl alloc]initWithItems:@[@"1",@"2",@"3"]];
        _segmentView.clipsToBounds = YES;
        _segmentView.layer.cornerRadius = 3.0;
        _segmentView.layer.borderWidth = 1;
        _segmentView.layer.borderColor = [[UIColor whiteColor]CGColor];
        _segmentView.frame = CGRectMake(kP6width(62), 26, kDEVICEWIDTH - 2*kP6width(62), 32);
        [_segmentView setBackgroundColor:[UIColor clearColor]];
        _segmentView.tintColor = TFCOLOR_3B98E0;
       
        // 正常的图片
        NSDictionary *dicNormal = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName,loadFont(16),NSFontAttributeName,nil];
        [_segmentView setTitleTextAttributes:dicNormal forState:UIControlStateNormal];
        [_segmentView setBackgroundImage:[CHUtil imageWithColor:[UIColor clearColor]] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
        
        NSDictionary *dicSelect = [NSDictionary dictionaryWithObjectsAndKeys:TFCOLOR_0093FF, NSForegroundColorAttributeName,loadFont(16),NSFontAttributeName,nil];
        [_segmentView setTitleTextAttributes:dicSelect forState:UIControlStateSelected];
        // 设置UISegmentedControl选中的图片
        [_segmentView setBackgroundImage:[CHUtil imageWithColor:[UIColor whiteColor]] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
        
        //去掉中间的分割线
        UIImage *_dividerImage= [CHUtil imageWithColor:TFCOLOR_0093FF];
        [_segmentView setDividerImage:_dividerImage forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
        
        [ _segmentView addTarget: self
                          action: @selector(controlPressed:)
                forControlEvents: UIControlEventValueChanged];
        [self.view addSubview:_segmentView];
    }
    [_segmentView setSelectedSegmentIndex:1];
}


你可能感兴趣的:(UISegmentedControl 去掉中间的分割线)