我有一个在图像上绘制文本的函数,但问题是当我调用这个函数时,它会给出一个错误“参数标签”(“,“)”与任何可用的重载都不匹配”
我是斯威夫特的新手,不知道怎么修理

func write_text_on_image(drawtext text:NSString , inimage img : UIImage , atpoint point : CGPoint) -> UIImage {

        let textcolor = UIColor.white
        let font = UIFont(name: "Helvetica", size: 16)

        let scale = UIScreen.main.scale
        UIGraphicsBeginImageContextWithOptions(img.size, false, scale)

        let font_attributes = [

            kCTFontAttributeName : font,
            kCTForegroundColorAttributeName : textcolor
        ]

      img.draw(in: CGRect(origin: CGPoint.zero, size: img.size))

        let rect = CGRect(origin: point, size: img.size)

        text.draw(in: rect, withAttributes: font_attributes as [NSAttributedString.Key : Any])

        let newimg = UIGraphicsGetImageFromCurrentImageContext()

        UIGraphicsEndPDFContext()

        return newimg!

    }

我把这个函数叫做
write_text_on_image(drawtext: "THis is some text", inimage: UIImage(named: "test.png")!, atpoint: CGPoint(20,20))[!

check out screen of function [swift - 参数标签与任何可用的重载都不匹配-LMLPHP]1

最佳答案

正如@vadian所说,代码完成将帮助您。这是我在操场上复制碎片得到的:

func write_text_on_image(drawtext text:NSString , inimage img : UIImage , atpoint point : CGPoint) -> UIImage { return UIImage() }

write_text_on_image(drawtext: "NSString", inimage: UIImage(), atpoint: CGPoint(x: 0, y: 0))

什么也不做,只是编译。

10-06 10:04