Created
January 18, 2019 01:54
-
-
Save Aymenworks/9c77c3ed0dbde7290773173d7dff0c59 to your computer and use it in GitHub Desktop.
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 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