如何更改 UIKit 中的 SF Symbol 图标颜色?
How to change SF Symbol icon color in UIKit?
在 SwiftUI
中,您可以使用 foregroundColor
修饰符更改图标的颜色:
Change the stroke/fill color of SF Symbol icon in SwiftUI?
有没有办法改变 UIKit
中的颜色?我查阅了文档,没有找到任何相关内容。
let configuration = UIImage.SymbolConfiguration(pointSize: 16, weight: .regular, scale: .medium)
let iconImage = UIImage(systemName: "chevron.right", withConfiguration: configuration)
使用:
let icon = UIImageView(image: iconImage.withRenderingMode(.alwaysTemplate))
icon.tintColor = .red
let iconImage = UIImage(systemName: "chevron.right",
withConfiguration: UIImage.SymbolConfiguration(pointSize: 16, weight: .regular, scale: .medium))?.withTintColor(.systemGreen)
使用以下代码更改 SFSymbols 图标颜色
let imageIcon = UIImage(systemName: "heart.fill")?.withTintColor(.red, renderingMode: .alwaysOriginal)
imageView.image = imageIcon
之前
之后
muteCall.setImage(UIImage(systemName: "mic.slash")?.withTintColor(.white, renderingMode: .alwaysOriginal), for: .normal)
将渲染设置为始终原始
let image = UIImage(systemName: "arrow.up.circle.fill")?.withTintColor(.black, renderingMode: .alwaysOriginal)
button.setImage(image, for: .normal)
@IBOutlet weak var downButton: UIButton!
downButton.setImage(UIImage(systemName: "chevron.down")?.withTintColor(.red, renderingMode: .alwaysOriginal), for: .normal)
在 SwiftUI
中,您可以使用 foregroundColor
修饰符更改图标的颜色:
Change the stroke/fill color of SF Symbol icon in SwiftUI?
有没有办法改变 UIKit
中的颜色?我查阅了文档,没有找到任何相关内容。
let configuration = UIImage.SymbolConfiguration(pointSize: 16, weight: .regular, scale: .medium)
let iconImage = UIImage(systemName: "chevron.right", withConfiguration: configuration)
使用:
let icon = UIImageView(image: iconImage.withRenderingMode(.alwaysTemplate))
icon.tintColor = .red
let iconImage = UIImage(systemName: "chevron.right",
withConfiguration: UIImage.SymbolConfiguration(pointSize: 16, weight: .regular, scale: .medium))?.withTintColor(.systemGreen)
使用以下代码更改 SFSymbols 图标颜色
let imageIcon = UIImage(systemName: "heart.fill")?.withTintColor(.red, renderingMode: .alwaysOriginal)
imageView.image = imageIcon
之前
之后
muteCall.setImage(UIImage(systemName: "mic.slash")?.withTintColor(.white, renderingMode: .alwaysOriginal), for: .normal)
将渲染设置为始终原始
let image = UIImage(systemName: "arrow.up.circle.fill")?.withTintColor(.black, renderingMode: .alwaysOriginal)
button.setImage(image, for: .normal)
@IBOutlet weak var downButton: UIButton!
downButton.setImage(UIImage(systemName: "chevron.down")?.withTintColor(.red, renderingMode: .alwaysOriginal), for: .normal)