Skip to content

Instantly share code, notes, and snippets.

@Aymenworks
Created January 18, 2019 01:54
Show Gist options
  • Save Aymenworks/9c77c3ed0dbde7290773173d7dff0c59 to your computer and use it in GitHub Desktop.
Save Aymenworks/9c77c3ed0dbde7290773173d7dff0c59 to your computer and use it in GitHub Desktop.
class SearchView: UIView {
// MARK: Properties
...
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()
// MARK: Setup
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 {
foregroundButton.layer.mask = shapeLayer
foregroundButton.layer.masksToBounds = true
}
layout: do {
addSubview(backgroundButton)
addSubview(foregroundButton)
backgroundButton.translatesAutoresizingMaskIntoConstraints = false
foregroundButton.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
backgroundButton.leadingAnchor.constraint(equalTo: leadingAnchor),
backgroundButton.topAnchor.constraint(equalTo: topAnchor),
backgroundButton.trailingAnchor.constraint(equalTo: trailingAnchor),
backgroundButton.bottomAnchor.constraint(equalTo: bottomAnchor),
foregroundButton.leftAnchor.constraint(equalTo: backgroundButton.leftAnchor),
foregroundButton.topAnchor.constraint(equalTo: backgroundButton.topAnchor),
foregroundButton.rightAnchor.constraint(equalTo: backgroundButton.rightAnchor),
foregroundButton.bottomAnchor.constraint(equalTo: backgroundButton.bottomAnchor),
])
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment