How to create an image from UILabel?

前端 未结 6 1817
情深已故
情深已故 2020-12-01 07:55

I\'m currently developing a simple photoshop like application on iphone. When I want to flatten my layers, the labels are at the good position but with a bad font size. Here

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 08:40

    for Swift, I use this UIView-extension:

    // Updated for Swift 3.0
    extension UIView {
        var grabbedImage:UIImage? {
            get {
                UIGraphicsBeginImageContextWithOptions(bounds.size, false, 0.0)
                layer.render(in: UIGraphicsGetCurrentContext()!)
                let img = UIGraphicsGetImageFromCurrentImageContext()
                UIGraphicsEndImageContext()
                return img
            }
        }
    }
    

提交回复
热议问题