我有一个在图像上绘制文本的函数,但问题是当我调用这个函数时它给出了一个错误“参数标签'(_:, _:)'不匹配任何可用的重载” 我是 swift 的新手,不知道如何修复
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))[!
最佳答案
正如@vadian 所说,代码补全会对您有所帮助。这是我在 Playground 中复制片段得到的结果:
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))
不执行任何操作,但会编译。
关于swift - 参数标签与任何可用的重载 swift 不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55650539/