参数标签与任何可用的重载都不匹配 swift
Argument labels do not match any available overloads swift
我有一个在图像上绘制文本的函数,但问题是当我调用这个函数时它给出了一个错误 "Argument labels '(_:, _:)' do not match any available overloads"
我是 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))[!
check out screen of function []1
正如@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))
不执行任何操作,但会编译。
CGPoint(x,y) 将参数作为 CGPoint(x : value,y ; value)
我有一个在图像上绘制文本的函数,但问题是当我调用这个函数时它给出了一个错误 "Argument labels '(_:, _:)' do not match any available overloads" 我是 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))[!
check out screen of function [
正如@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))
不执行任何操作,但会编译。
CGPoint(x,y) 将参数作为 CGPoint(x : value,y ; value)