I have the following requirement where I am trying to create an Image with Text under the picture/icon as such:
Image(
size: CGSize(width: 60, height: 60),
label: Text("Set Paid").foregroundStyle(Color.white).font(.caption)
) { ctx in
ctx.draw(
Image("icon-dollar"),
at: CGPoint(x: 50, y: 0),
anchor: .top
)
ctx.draw(
Text("Set Paid"),
at: CGPoint(x: 30, y: 60),
anchor: .top
)
}
My issue is that the image:
ctx.draw(
Image("icon-dollar"),
at: CGPoint(x: 50, y: 0),
anchor: .top
)
is 80×80.
Is there something i can do to "resize" that image with the ctx.draw function?!
>Solution :
Try using the draw function that takes a CGRect instead of a CGPoint, draw(_:in:style:):
ctx.draw(
Image("icon-dollar"),
in: CGRect(
origin: CGPoint(x: 40, y: 0),
size: CGSize(width: 20, height: 20)
)
)