1

i have a function which draw text on image but issue is when i call this function it gives a error "Argument labels '(_:, _:)' do not match any available overloads" i am new to swift and dont know how to fix

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!

    }

i am calling this func as

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

Naqeeb
  • 1,121
  • 8
  • 25
  • 3
    It's `CGPoint(x: 20, y: 20)`. – Sweeper Apr 12 '19 at 11:25
  • 1
    How about using Code Completion? Type `CGPoint(` and see what Xcode suggests. By the way this is not javascript. Please use *lowerCamelCased* variable and function names, native Swift types and avoid redundant information for example `func write(text: String, in img : UIImage, at point : CGPoint) -> UIImage` – vadian Apr 12 '19 at 11:33
  • @vadian thanks for suggestion actually i m just a beginner i try my best to avoid these – Naqeeb Apr 12 '19 at 11:44

2 Answers2

1

As @vadian said, code completion would help you. This is what I got from duplicating a fragment in 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))

Doesn't do anything, but compiles.

Ron
  • 660
  • 1
  • 5
  • 10
1

CGPoint(x,y) pass perameter as CGPoint(x : value,y ; value)

Goal Tech
  • 167
  • 9