Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SwiftUI draw function issue

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)
    )
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading