How to change SF Symbol icon color in UIKit?

francisfeng picture francisfeng · Oct 6, 2019 · Viewed 14.9k times · Source

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)

Answer

ShigaSuresh picture ShigaSuresh · Apr 22, 2020

Use below code for changing SFSymbols icons color

let imageIcon = UIImage(systemName: "heart.fill")?.withTintColor(.red, renderingMode: .alwaysOriginal)
    imageView.image = imageIcon

Before

enter image description here

After

enter image description here