swift - 参数标签与任何可用的重载 swift 不匹配

标签 swift cgrect cgpoint drawtext uigraphicscontext

我有一个在图像上绘制文本的函数,但问题是当我调用这个函数时它给出了一个错误“参数标签'(_:, _:)'不匹配任何可用的重载” 我是 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 [calling 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))

不执行任何操作,但会编译。

关于swift - 参数标签与任何可用的重载 swift 不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55650539/

相关文章:

iphone - SQLite 的 NSArray 绘制 CGRects

iphone - 具有多个 UIImageView 实例的 iOS CGRectIntersectsRect?

iphone - 如何测试一个点是否在 View 中

ios - CGPoint的小数部分是什么意思?

ios - 带有与 ViewController 分离的 Controller 的 UITableView

objective-c - networkextension 不导入较新的版本

ios - 设置 CGRect 的优先级 - Swift

swift - Cocoa 从 AppDelegate 快速加载 ViewController 和 Storyboard View

objective-c - 将基元分配给 NSManagedObject 实例 (Swift)

ios - 从 UIBezierPath 获取所有点(不仅仅是控制点)