Skip to content

Instantly share code, notes, and snippets.

@apatronl
Last active June 14, 2020 22:02
Show Gist options
  • Save apatronl/006fc0452760d433be95835858f2aaa4 to your computer and use it in GitHub Desktop.
Save apatronl/006fc0452760d433be95835858f2aaa4 to your computer and use it in GitHub Desktop.
class ButtonPanelView: UIView {
// ...
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = UIColor(red: 81/255, green: 166/255, blue: 219/255, alpha: 1)
layer.cornerRadius = buttonSize / 2
layer.shadowColor = UIColor.lightGray.cgColor
layer.shadowOpacity = shadowOpacity
layer.shadowOffset = .zero
addSubview(containerStackView)
setConstraints()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setConstraints() {
// Main button
menuButton.translatesAutoresizingMaskIntoConstraints = false
menuButton.widthAnchor.constraint(equalToConstant: buttonSize).isActive = true
menuButton.heightAnchor.constraint(equalToConstant: buttonSize).isActive = true
// Dog button
dogButton.translatesAutoresizingMaskIntoConstraints = false
dogButton.widthAnchor.constraint(equalToConstant: buttonSize).isActive = true
dogButton.heightAnchor.constraint(equalToConstant: buttonSize).isActive = true
// Cat button
catButton.translatesAutoresizingMaskIntoConstraints = false
catButton.widthAnchor.constraint(equalToConstant: buttonSize).isActive = true
catButton.heightAnchor.constraint(equalToConstant: buttonSize).isActive = true
// Container stack view
containerStackView.translatesAutoresizingMaskIntoConstraints = false
containerStackView.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
containerStackView.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
translatesAutoresizingMaskIntoConstraints = false
self.widthAnchor.constraint(equalTo: containerStackView.widthAnchor).isActive = true
self.heightAnchor.constraint(equalTo: containerStackView.heightAnchor).isActive = true
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment