SwiftUI(6)Image
2023-03-08 本文已影响0人
Z小新
系统图标
Image(systemName: "heart.fill")// 名
.font(.system(size: 30))// 大小
// .scaledToFill()
.aspectRatio( contentMode: .fit)
.scaledToFit()
.foregroundColor(.red)// 颜色
.frame(width: 200,height: 200)// frame

自定义图标
添加自定义图标。黑色的字母G.

自定义图标
Image("G")// 名
.renderingMode(.template)// 允许渲染颜色
.font(.system(size: 30))// 大小
// .scaledToFill()
.aspectRatio( contentMode: .fit)
.scaledToFit()
.foregroundColor(.green)// 颜色
.frame(width: 200,height: 200)// frame
展示:
通过修改foregroundColor属性,可随意修改图片颜色


图片展示
不做限制按照原始大小展示
Image("dog")

调整图片 大小 缩放mode
Image("dog")// 名
.resizable()//适应大小
.aspectRatio( contentMode: .fill)
// .scaledToFit()// 自适应宽高
.frame(width: 200,height: 200)// frame
.cornerRadius(100)// 圆角
