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)
For a full overview of the available SF Symbols that are available, including the newly added and multicolor symbols, download the SF Symbols 2 app from Apple's SF Symbols page. To use a multicolored symbol in your app, all you need to do is set the correct rendering mode for your image.
setBlendMode(. multiply) ctx. draw(image. cgImage!, in: imageRect) let newImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return newImage! } }
Use below code for changing SFSymbols icons color
let imageIcon = UIImage(systemName: "heart.fill")?.withTintColor(.red, renderingMode: .alwaysOriginal) imageView.image = imageIcon
Before
After
Use:
let icon = UIImageView(image: iconImage.withRenderingMode(.alwaysTemplate)) icon.tintColor = .red
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With