How to prevent backgroundColor of UISegmentedControl bleeding beyond segmented border How to prevent backgroundColor of UISegmentedControl bleeding beyond segmented border ios ios

How to prevent backgroundColor of UISegmentedControl bleeding beyond segmented border


Set the segment control's layer's corner radius to 4.0. It should help. You may need to import QuartzCore to be able to access the layer's properties.

segment.layer.cornerRadius = 4.0;segment.clipsToBounds = YES;


Set segment control layer corner radius to 5. and ClipsToBounds YES .

segmentController.layer.cornerRadius = 5;    segmentController.clipsToBounds = YES;

Hope its work for you


the best result I could achieve in Swift:

    segmentedControl.layer.cornerRadius = 4    let mask = CAShapeLayer()    mask.frame = CGRectMake(0, 0, segmentedControl.bounds.size.width-1, segmentedControl.bounds.size.height);    let maskPath = UIBezierPath(roundedRect: mask.frame,                                byRoundingCorners: [.BottomLeft, .BottomRight, .TopLeft, .TopRight],                                cornerRadii: CGSize(width: 4.0, height: 4.0))    mask.path = maskPath.CGPath    segmentedControl.layer.mask = mask