Skip to content

Instantly share code, notes, and snippets.

@samuelbeek
Last active November 18, 2015 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samuelbeek/ea3cf6e6e8849981485c to your computer and use it in GitHub Desktop.
Save samuelbeek/ea3cf6e6e8849981485c to your computer and use it in GitHub Desktop.
Remove Segmented Control
// src: http://stackoverflow.com/questions/31651983/swift-how-to-remove-border-from-segmented-control
import UIKit
extension UISegmentedControl {
func removeBorders() {
setBackgroundImage(imageWithColor(backgroundColor!), forState: .Normal, barMetrics: .Default)
setBackgroundImage(imageWithColor(tintColor!), forState: .Selected, barMetrics: .Default)
setDividerImage(imageWithColor(UIColor.clearColor()), forLeftSegmentState: .Normal, rightSegmentState: .Normal, barMetrics: .Default)
}
// create a 1x1 image with this color
private func imageWithColor(color: UIColor) -> UIImage {
let rect = CGRectMake(0.0, 0.0, 1.0, 1.0)
UIGraphicsBeginImageContext(rect.size)
let context = UIGraphicsGetCurrentContext()
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextFillRect(context, rect);
let image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment