Skip to content

Instantly share code, notes, and snippets.

@alanf
Last active September 29, 2017 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanf/3e01633d1e62ad102043e807b9dcce65 to your computer and use it in GitHub Desktop.
Save alanf/3e01633d1e62ad102043e807b9dcce65 to your computer and use it in GitHub Desktop.
import Foundation
import UIKit
@IBDesignable class GradientView: UIView {
let titleLabel = UILabel()
@IBInspectable var title: String? = nil {
didSet {
titleLabel.text = title
}
}
override func layoutSubviews() {
super.layoutSubviews()
// Necessary in layoutSubviews to get the proper frame size.
configure()
}
func configure() {
let gradient = CAGradientLayer()
gradient.frame = bounds
gradient.colors = [UIColor(red: 0.066_6, green: 0.066_6, blue: 0.066_6, alpha: 1.0).cgColor,
UIColor(red: 0.313_7, green: 0.313_7, blue: 0.333_3, alpha: 1.0).cgColor]
gradient.startPoint = CGPoint(x: 0.0, y: 0.0)
gradient.endPoint = CGPoint(x: 0.0, y: 0.9)
layer.insertSublayer(gradient, at: 0)
let titleFont = UIFont(name: "Montserrat-Medium", size: 16) ?? UIFont.boldSystemFont(ofSize: 16)
titleLabel.font = titleFont
titleLabel.textColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.86)
addSubview(titleLabel)
layout.centerHorizontally(titleLabel)
layout.top(titleLabel, top: 23.3)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment