代码之家  ›  专栏  ›  技术社区  ›  Learn2Code

SwiftUI绘图功能问题

  •  0
  • Learn2Code  · 技术社区  · 1 年前

    当我试图在图片/图标下创建带文本的图像时,我有以下要求:

    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
        )
    
    }
    

    我的问题是图像:

    ctx.draw(
        Image("icon-dollar"),
        at: CGPoint(x: 50, y: 0),
        anchor: .top
    )
    

    是80x80。

    我能用ctx.draw函数“调整”图像的大小吗?!

    1 回复  |  直到 1 年前
        1
  •  0
  •   Benzy Neez    1 年前

    尝试使用draw函数 CGRect 而不是 CGPoint , draw(_:in:style:) :

    ctx.draw(
        Image("icon-dollar"),
        in: CGRect(
            origin: CGPoint(x: 40, y: 0),
            size: CGSize(width: 20, height: 20)
        )
    )