Skip to content

Instantly share code, notes, and snippets.

@Shubham0812
Last active June 28, 2020 05:37
Show Gist options
  • Save Shubham0812/b0450f0a5722e6a14fa90347d5130c85 to your computer and use it in GitHub Desktop.
Save Shubham0812/b0450f0a5722e6a14fa90347d5130c85 to your computer and use it in GitHub Desktop.
extension UIButton {
// iconName - SFSymbol Name
// size - Size of the Symbol in points
// scale - .small, .medium, .large
// weight - .ultralight, .thin, .light, .regular, .medium, .semibold, .bold, .heavy, .black
// tintColor - Color of the Symbol
// backgroundColor - Background color of the button
func setSFSymbol(iconName: String, size: CGFloat, weight: UIImage.SymbolWeight,
scale: UIImage.SymbolScale, tintColor: UIColor, backgroundColor: UIColor) {
let symbolConfiguration = UIImage.SymbolConfiguration(pointSize: size, weight: weight, scale: scale)
let buttonImage = UIImage(systemName: iconName, withConfiguration: symbolConfiguration)
self.setImage(buttonImage, for: .normal)
self.tintColor = tintColor
self.backgroundColor = backgroundColor
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment