Drawing NSString to UIImage

前端 未结 4 1873
梦毁少年i
梦毁少年i 2021-01-25 04:54

I have a NSString object. I want to write it to existing UIImage object. UIImage object already has some image associate with it. I want to write string to same image. How do i

4条回答
  •  萌比男神i
    2021-01-25 05:34

    You would draw (composite) both the image and the string into a graphics context, and then grab the resulting UIImage.

    To draw the image use renderInContext. To draw the text use CGContextShowTextAtPoint. To get the resulting image

    UIImage *compositeImage = UIGraphicsGetImageFromCurrentImageContext();
    

提交回复
热议问题