Remove UISegmentedControl separators completely. (iphone)

前端 未结 9 1677
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:52

    I have used segmentcontrol.tintColor = [UIColor clearColor]; with iOS7 and it seems to work.

    0 讨论(0)
  • 2020-12-05 05:56

    The following code will do exactly what you want.

    UIGraphicsBeginImageContextWithOptions(CGSizeMake(1, self.segControlOut.frame.size.height), NO, 0.0);
    UIImage *blank = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [self.segControlOut setDividerImage:blank
                    forLeftSegmentState:UIControlStateNormal
                      rightSegmentState:UIControlStateNormal
                             barMetrics:UIBarMetricsDefault];
    
    0 讨论(0)
  • 2020-12-05 05:56
    - (void) configSegmentControl {
        [segmentControl setBackgroundImage:[self imageWithColor:[UIColor blueColor]] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
        [segmentControl setBackgroundImage:[self imageWithColor:[UIColor redColor]] forState:UIControlStateSelected  barMetrics:UIBarMetricsDefault];
        segmentControl.layer.cornerRadius = 4.0f;
        segmentControl.clipsToBounds = YES;
    }
    
    - (UIImage *)imageWithColor:(UIColor *)color {
        CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
        UIGraphicsBeginImageContext(rect.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
    
        CGContextSetFillColorWithColor(context, [color CGColor]);
        CGContextFillRect(context, rect);
    
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        return image;
    }
    
    0 讨论(0)
提交回复
热议问题