Reputation: 808
In SwiftUI
, you can change the icon's color using foregroundColor
modifier:
Change the stroke/fill color of SF Symbol icon in SwiftUI?
Is there a way to change the color in UIKit
? I looked up the documentation and didn't find anything related to it.
let configuration = UIImage.SymbolConfiguration(pointSize: 16, weight: .regular, scale: .medium)
let iconImage = UIImage(systemName: "chevron.right", withConfiguration: configuration)
Upvotes: 54
Views: 28516
Reputation: 371
A small addition. I'm glad if it helps anyone. We can combine not only different colours, but also different sizes and weight. For example you can do this:
let colorsConfig = UIImage.SymbolConfiguration(paletteColors: [.white, .magenta])
let sizeConfig = UIImage.SymbolConfiguration(pointSize: 30, weight: .bold)
let image = UIImage(systemName: "plus.circle.fill", withConfiguration: colorsConfig.applying(sizeConfig))
button.setImage(image, for: .normal)
Upvotes: 21
Reputation: 1768
Use below code for changing SFSymbols icons color
let imageIcon = UIImage(systemName: "heart.fill")?.withTintColor(.red, renderingMode: .alwaysOriginal)
imageView.image = imageIcon
Before
After
Upvotes: 91
Reputation: 4608
Use:
let icon = UIImageView(image: iconImage.withRenderingMode(.alwaysTemplate))
icon.tintColor = .red
Upvotes: 46