在SwiftUI
中,您可以使用foregroundColor
修饰符更改图标的颜色。因此,我认为应该有一种方法可以更改UIKit
中的颜色。我查阅了文档,却没有找到任何相关文件。
现在可以吗?
let iconImage = UIImage(systemName: "chevron.right",
withConfiguration: UIImage.SymbolConfiguration(pointSize: 16, weight: .regular, scale: .medium))
答案 0 :(得分:19)
使用以下代码更改SFSymbols图标的颜色
let imageIcon = UIImage(systemName: "heart.fill")?.withTintColor(.red, renderingMode: .alwaysOriginal)
imageView.image = imageIcon
之前
之后
答案 1 :(得分:4)
使用:
let icon = UIImageView(image: iconImage.withRenderingMode(.alwaysTemplate))
icon.tintColor = .red
答案 2 :(得分:3)
let iconImage = UIImage(systemName: "chevron.right",
withConfiguration: UIImage.SymbolConfiguration(pointSize: 16, weight: .regular, scale: .medium))?.withTintColor(.systemGreen)
答案 3 :(得分:2)
muteCall.setImage(UIImage(systemName: "mic.slash")?.withTintColor(.white, renderingMode: .alwaysOriginal), for: .normal)
将渲染设置为始终原始
答案 4 :(得分:1)
let image = UIImage(systemName: "arrow.up.circle.fill")?.withTintColor(.black, renderingMode: .alwaysOriginal)
button.setImage(image, for: .normal)