Skip to content

Instantly share code, notes, and snippets.

@xmhafiz
Created March 7, 2023 19:05
Show Gist options
  • Save xmhafiz/46ae1209c520215bcfeb8dae62557e59 to your computer and use it in GitHub Desktop.
Save xmhafiz/46ae1209c520215bcfeb8dae62557e59 to your computer and use it in GitHub Desktop.
import UIKit
class ViewController: UIViewController {
// After connected from storyboard to this class
@IBOutlet weak var contentStackView: UIStackView!
override func viewDidLoad() {
super.viewDidLoad()
// Add GradientButton programatically
let gradientButton = GradientButton()
gradientButton.startColor = UIColor.red
gradientButton.endColor = UIColor.yellow
gradientButton.setTitle("Button", for: .normal)
// Set constraint height
gradientButton.heightAnchor.constraint(equalToConstant: 50).isActive = true
// Add the button to the stack view
contentStackView.addArrangedSubview(gradientButton)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment