Skip to content

Instantly share code, notes, and snippets.

@Aymenworks
Created January 17, 2019 13:38
Show Gist options
  • Save Aymenworks/c7131a4a74e8caa872c85d50182f13f4 to your computer and use it in GitHub Desktop.
Save Aymenworks/c7131a4a74e8caa872c85d50182f13f4 to your computer and use it in GitHub Desktop.
struct Colors {
static let backgroundButtonBackgroundColor = UIColor.clear
static let backgroundButtonTintColor = #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1)
static let foregroundButtonBackgroundColor = #colorLiteral(red: 1, green: 0.8, blue: 0, alpha: 1)
static let foregroundButtonTintColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
}
let shapeLayer = CAShapeLayer()
let backgroundButton = UIButton()
let foregroundButton = UIButton()
func setup() {
UI: do {
backgroundButton.setImage(UIImage(named: "search"), for: .normal)
backgroundButton.backgroundColor = Colors.backgroundButtonBackgroundColor
backgroundButton.tintColor = Colors.backgroundButtonTintColor
foregroundButton.setImage(UIImage(named: "search"), for: .normal)
foregroundButton.backgroundColor = Colors.foregroundButtonBackgroundColor
foregroundButton.tintColor = Colors.foregroundButtonTintColor
}
layers: do {
// the shape layer ( mask ) will hide/show the foreground button depending on the scroll animation progress
foregroundButton.layer.mask = shapeLayer
foregroundButton.layer.masksToBounds = true
}
layout: do {
addSubview(backgroundButton)
addSubview(foregroundButton)
// layout buttons using autolayout there
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment