Created
October 10, 2014 20:17
-
-
Save mbuff24/f2b473f1c76b798ae644 to your computer and use it in GitHub Desktop.
Making a capture style button with a UIView and 2 CALayers
This file contains hidden or 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
class MainController: UIViewController { | |
@IBOutlet weak var captureButton: UIView? | |
let BORDER_WIDTH:CGFloat = 4 | |
let RADIUS_MULTIPLIER:CGFloat = 0.5 | |
let BUTTON_COLOR = UIColor.redColor().CGColor | |
let BUTTON_PRESSED_COLOR = UIColor.whiteColor().CGColor | |
let INNER_BUTTON_OFFSET = 0.4 | |
var outerBtnLayer:CALayer = CALayer() | |
var innerBtn:CALayer = CALayer() | |
override func viewDidLoad() { | |
let buttonWidth = captureButton!.bounds.size.width; | |
let centerPoint:CGPoint = CGPointMake(buttonWidth / 2, buttonWidth / 2) | |
outerBtnLayer.bounds = captureButton!.frame | |
outerBtnLayer.borderColor = BUTTON_COLOR | |
outerBtnLayer.borderWidth = BORDER_WIDTH | |
outerBtnLayer.cornerRadius = buttonWidth * RADIUS_MULTIPLIER | |
outerBtnLayer.masksToBounds = true | |
outerBtnLayer.position = centerPoint; | |
captureButton?.layer.addSublayer(outerBtnLayer) | |
innerBtn.bounds = CGRect(x: buttonWidth * 0.2, y: buttonWidth * 0.2, width: buttonWidth * 0.8, height: buttonWidth * 0.8) | |
innerBtn.backgroundColor = BUTTON_COLOR | |
innerBtn.cornerRadius = innerBtn.bounds.size.width * RADIUS_MULTIPLIER | |
innerBtn.masksToBounds = true | |
innerBtn.position = centerPoint; | |
captureButton?.layer.addSublayer(innerBtn) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment