如何在 SwiftUI 中设置图像色调? [英] How can I set an image tint in SwiftUI?

查看:33
本文介绍了如何在 SwiftUI 中设置图像色调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 SwiftUI Image 类中设置图像色调

I am trying to set an image tint in SwiftUI Image class

对于 UIKit,我可以使用

For UIKit, I can set image tint using

let image = UIImage(systemName: "cart")!.withTintColor(.blue)

但我在 swiftui 文档中找不到这样的设置

but I cant find such settings in swiftui docs

推荐答案

On new swiftUI for set tint use:

On new swiftUI for set tint use:

Image("ImageName")
  .foregroundColor(.red)

根据源图像,您可能还需要额外的渲染模式修饰符:

Depending on the source image you may also need an additional rendering mode modifier:

Image("ImageName")
  .renderingMode(.template)
  .colorMultiply(.red)
// or
Image("ImageName")
  .colorMultiply(.blue)

你可以阅读这个 主题.

这篇关于如何在 SwiftUI 中设置图像色调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆