Last active
November 18, 2015 11:01
-
-
Save samuelbeek/ea3cf6e6e8849981485c to your computer and use it in GitHub Desktop.
Remove Segmented Control
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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