Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change SF Symbol icon color in UIKit?

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) 
like image 286
francisfeng Avatar asked Oct 06 '19 09:10

francisfeng


People also ask

How do you use multicolor SF Symbols?

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.

How do I change the UIImage color in Objective C?

setBlendMode(. multiply) ctx. draw(image. cgImage!, in: imageRect) let newImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return newImage! } }


2 Answers

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

like image 77
ShigaSuresh Avatar answered Oct 07 '22 03:10

ShigaSuresh


Use:

let icon = UIImageView(image: iconImage.withRenderingMode(.alwaysTemplate)) icon.tintColor = .red 
like image 41
Yonat Avatar answered Oct 07 '22 03:10

Yonat