如何在swift 3中使用imageview嵌套标签

时间:2016-10-19 02:08:54

标签: swift imageview save swift3 photo

以下代码可以拍摄照片并将其保存到照片库。此代码还具有覆盖图像视图的标签,但它只是覆盖图像的顶部,而不是保存在图像上。如何嵌套标签,以便在保存照片时,文本和图像都位于照片库中的最终照片中。

config.vm.provision :puppet do |puppet|
    puppet.manifests_path = "vagrant/manifests"
    puppet.manifest_file  = "site.pp"
    puppet.module_path = "vagrant/modules"
    puppet.options = "--verbose --debug"
end

1 个答案:

答案 0 :(得分:1)

您应该使用以下文字绘制图像:

    let str = "I'am a test label" as NSString
    let rect = CGRect(origin: CGPoint.zero, size: image.image!.size)
    UIGraphicsBeginImageContextWithOptions(rect.size, false, 0)
    image.image!.draw(in: rect)
    //str.draw(in: <#The Rect You want#>, withAttributes: <#Specify The Font And Color Or Other Property#>)
    str.draw(in: CGRect(origin: CGPoint.zero, size: CGSize(width: 200, height: 40)), withAttributes: [NSFontAttributeName:UIFont.systemFont(ofSize: 20), NSForegroundColorAttributeName:UIColor.green])
    let img = UIGraphicsGetImageFromCurrentImageContext()!
    UIGraphicsEndImageContext()

    let imageData = UIImagePNGRepresentation(img)
    let compressedImage = UIImage(data:  imageData!)
    UIImageWriteToSavedPhotosAlbum(compressedImage!, nil, nil, nil)