Here is the code and it is really slow, like seconds slow to render about 25 labels.

extension UILabel{
    func deBlur(){
        for subview in self.subviews {
            if (subview.tag == 99999) {

    func blur(){
        let  blurRadius:CGFloat = 5.1

        layer.render(in: UIGraphicsGetCurrentContext()!)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        let blurFilter = CIFilter(name: "CIGaussianBlur")
        let imageToBlur = CIImage(cgImage: (image?.cgImage)!)
        blurFilter?.setValue(imageToBlur, forKey: kCIInputImageKey)
        blurFilter?.setValue(blurRadius, forKey: "inputRadius")
        let outputImage: CIImage? = blurFilter?.outputImage
        let context = CIContext(options: nil)
        let cgimg = context.createCGImage(outputImage!, from: (outputImage?.extent)!)
        layer.contents = cgimg!

So this takes way too much time. For 20 labels it takes seconds on the simulator.

  • \$\begingroup\$ Is the deBlur() method unrelated to the blur()? \$\endgroup\$ – kelin Dec 4 '17 at 20:52
  • \$\begingroup\$ First of all you can draw all labels in a single context, because context creation requires memory allocation which is quite slow. \$\endgroup\$ – kelin Dec 4 '17 at 20:54
  • \$\begingroup\$ Try using EAGLContext based on GPU Apple Doc \$\endgroup\$ – Coder ACJHP May 23 '19 at 10:14
  • \$\begingroup\$ EAGLContext has been deprecated \$\endgroup\$ – Glass Oct 5 '20 at 0:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.