MST
星途 面试题库

面试题:Swift中SwiftUI如何加载本地图片资源并设置其颜色

在SwiftUI中,假设项目中有一张名为 'example.jpg' 的本地图片,如何使用 `Image` 加载该图片,并通过某种方式为其设置一种特定的颜色(例如红色),请写出相关代码实现。
27.5万 热度难度
编程语言Swift

知识考点

AI 面试

面试题答案

一键面试
import SwiftUI

struct ContentView: View {
    var body: some View {
        Image("example")
           .renderingMode(.template)
           .foregroundColor(.red)
    }
}