簡體   English   中英

如何更改 UIKit 中 SF Symbols 的圖標顏色?

[英]How to change SF Symbols' icon color in UIKit?

SwiftUI中,您可以使用foregroundColor修飾符更改圖標的顏色。 所以我認為應該有一種方法可以改變UIKit的顏色。 我查閱了文檔並沒有找到任何相關的內容。

現在有可能嗎?

let iconImage = UIImage(systemName: "chevron.right", 
    withConfiguration: UIImage.SymbolConfiguration(pointSize: 16, weight: .regular, scale: .medium))

使用以下代碼更改 SFSymbols 圖標顏色

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

在此處輸入圖像描述

在此處輸入圖像描述

利用:

let icon = UIImageView(image: iconImage.withRenderingMode(.alwaysTemplate))
icon.tintColor = .red
muteCall.setImage(UIImage(systemName: "mic.slash")?.withTintColor(.white, renderingMode: .alwaysOriginal), for: .normal)

將渲染設置為始終原始

let iconImage = UIImage(systemName: "chevron.right",
                                            withConfiguration: UIImage.SymbolConfiguration(pointSize: 16, weight: .regular, scale: .medium))?.withTintColor(.systemGreen)
let image = UIImage(systemName: "arrow.up.circle.fill")?.withTintColor(.black, renderingMode: .alwaysOriginal)
button.setImage(image, for: .normal)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM