Remove UISegmentedControl separators completely. (iphone)

前端 未结 9 1675
Happy的楠姐
Happy的楠姐 2020-12-05 05:30

Is there a way to completely remove the line separating the two segments in a UISegmentedControl?

Setting the segmentedControlStyle is not helping.

9条回答
  •  有刺的猬
    2020-12-05 05:37

    @naveed's and @Jon Setting's answers saved my day!

    But as a bit of a perfectionist, i was frustrated to find out that this code also leaves holes in the outer border of the control:

    So I added a few lines of code to get rid of those and make it look neat:

    The complete code for this would be

    CGFloat h = self.segControlOut.frame.size.height;
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(1, h), NO, 0.0);
    
    // draw the missing dots with the control border color
    [self.segControlOut.tintColor set];
    UIRectFrame( CGRectMake(0, -1, 1, 2.5) );
    UIRectFrame( CGRectMake(0, h-1.5, 1, 2.5) );
    
    UIImage *blank = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [self.segControlOut setDividerImage:blank
                    forLeftSegmentState:UIControlStateNormal
                      rightSegmentState:UIControlStateNormal
                             barMetrics:UIBarMetricsDefault];
    

提交回复
热议问题