Skip to content

Instantly share code, notes, and snippets.

View kaiserabliz's full-sized avatar
https://shorturl.at/asuZ3

Kaiser kaiserabliz

https://shorturl.at/asuZ3
View GitHub Profile
@IBOutlet weak var myBarButton: UIBarButtonItem! {
didSet {
let icon = UIImage(named: "refresh")
let iconSize = CGRect(origin: .zero, size: icon!.size)
let iconButton = UIButton(frame: iconSize)
iconButton.setBackgroundImage(icon, for: .normal)
refreshBarButton.customView = iconButton
iconButton.addTarget(self, action: #selector(<Action here>), for: .touchUpInside)
}
}
// MARK: - UIView extensions
extension UIView {
func gradientBackground(from color1: UIColor, to color2: UIColor, direction: GradientDirection) {
let gradient = CAGradientLayer()
gradient.frame = self.bounds
gradient.colors = [color1.cgColor, color2.cgColor]
switch direction {
case .leftToRight:
gradient.startPoint = CGPoint(x: 0.0, y: 0.5)
gradient.endPoint = CGPoint(x: 1.0, y: 0.5)