iOS blur effect to ImageView with Swift












3















I am trying to make simple iOS app. I need to make image view with blur effect.
I found this code on Stack Overflow:



class BlurImageView: UIImageView {

override func awakeFromNib() {
super.awakeFromNib()
}

required init(coder aDecoder: NSCoder!){
super.init(coder: aDecoder)
var blur:UIBlurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light)
var effectView:UIVisualEffectView = UIVisualEffectView (effect: blur)
effectView.frame = frame
addSubview(effectView)
}
}


And I need to connect this class to my image_view, but I don't know how to do it.
I try to do it in my view_did_load function in my ViewController (image_view is a outlet)



override func viewDidLoad() {
super.viewDidLoad()
image_view = BlurImageView()
}


but NSCoder required... What is it? maybe my way is a wrong way?










share|improve this question

























  • Added blur effect with stackoverflow.com/questions/24067719/…

    – mr_ivan777
    Aug 14 '14 at 21:10
















3















I am trying to make simple iOS app. I need to make image view with blur effect.
I found this code on Stack Overflow:



class BlurImageView: UIImageView {

override func awakeFromNib() {
super.awakeFromNib()
}

required init(coder aDecoder: NSCoder!){
super.init(coder: aDecoder)
var blur:UIBlurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light)
var effectView:UIVisualEffectView = UIVisualEffectView (effect: blur)
effectView.frame = frame
addSubview(effectView)
}
}


And I need to connect this class to my image_view, but I don't know how to do it.
I try to do it in my view_did_load function in my ViewController (image_view is a outlet)



override func viewDidLoad() {
super.viewDidLoad()
image_view = BlurImageView()
}


but NSCoder required... What is it? maybe my way is a wrong way?










share|improve this question

























  • Added blur effect with stackoverflow.com/questions/24067719/…

    – mr_ivan777
    Aug 14 '14 at 21:10














3












3








3


3






I am trying to make simple iOS app. I need to make image view with blur effect.
I found this code on Stack Overflow:



class BlurImageView: UIImageView {

override func awakeFromNib() {
super.awakeFromNib()
}

required init(coder aDecoder: NSCoder!){
super.init(coder: aDecoder)
var blur:UIBlurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light)
var effectView:UIVisualEffectView = UIVisualEffectView (effect: blur)
effectView.frame = frame
addSubview(effectView)
}
}


And I need to connect this class to my image_view, but I don't know how to do it.
I try to do it in my view_did_load function in my ViewController (image_view is a outlet)



override func viewDidLoad() {
super.viewDidLoad()
image_view = BlurImageView()
}


but NSCoder required... What is it? maybe my way is a wrong way?










share|improve this question
















I am trying to make simple iOS app. I need to make image view with blur effect.
I found this code on Stack Overflow:



class BlurImageView: UIImageView {

override func awakeFromNib() {
super.awakeFromNib()
}

required init(coder aDecoder: NSCoder!){
super.init(coder: aDecoder)
var blur:UIBlurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light)
var effectView:UIVisualEffectView = UIVisualEffectView (effect: blur)
effectView.frame = frame
addSubview(effectView)
}
}


And I need to connect this class to my image_view, but I don't know how to do it.
I try to do it in my view_did_load function in my ViewController (image_view is a outlet)



override func viewDidLoad() {
super.viewDidLoad()
image_view = BlurImageView()
}


but NSCoder required... What is it? maybe my way is a wrong way?







ios swift uiimageview blur






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 29 '18 at 11:41









Shruti Thombre

8311823




8311823










asked Aug 14 '14 at 20:45









mr_ivan777mr_ivan777

1861717




1861717













  • Added blur effect with stackoverflow.com/questions/24067719/…

    – mr_ivan777
    Aug 14 '14 at 21:10



















  • Added blur effect with stackoverflow.com/questions/24067719/…

    – mr_ivan777
    Aug 14 '14 at 21:10

















Added blur effect with stackoverflow.com/questions/24067719/…

– mr_ivan777
Aug 14 '14 at 21:10





Added blur effect with stackoverflow.com/questions/24067719/…

– mr_ivan777
Aug 14 '14 at 21:10












2 Answers
2






active

oldest

votes


















1














You need to make your image_view an instance of BlurImageView, so in your view controller and where your image_view is an outlet, you need to make it an instance of BlurImageView and not an instance of an UIImageView.






share|improve this answer































    5














    You don't need it. The reason why you're not seeing results is because you're attempting to initialize the class from a different initializer than the one you setup.



    Try:



    class BlurImageView: UIImageView {

    override func awakeFromNib() {
    super.awakeFromNib()
    }

    override init() {
    var blur:UIBlurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light)
    var effectView:UIVisualEffectView = UIVisualEffectView (effect: blur)
    effectView.frame = frame
    addSubview(effectView)
    }
    }





    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f25317292%2fios-blur-effect-to-imageview-with-swift%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      You need to make your image_view an instance of BlurImageView, so in your view controller and where your image_view is an outlet, you need to make it an instance of BlurImageView and not an instance of an UIImageView.






      share|improve this answer




























        1














        You need to make your image_view an instance of BlurImageView, so in your view controller and where your image_view is an outlet, you need to make it an instance of BlurImageView and not an instance of an UIImageView.






        share|improve this answer


























          1












          1








          1







          You need to make your image_view an instance of BlurImageView, so in your view controller and where your image_view is an outlet, you need to make it an instance of BlurImageView and not an instance of an UIImageView.






          share|improve this answer













          You need to make your image_view an instance of BlurImageView, so in your view controller and where your image_view is an outlet, you need to make it an instance of BlurImageView and not an instance of an UIImageView.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 14 '14 at 20:52









          BHendricksBHendricks

          3,25052252




          3,25052252

























              5














              You don't need it. The reason why you're not seeing results is because you're attempting to initialize the class from a different initializer than the one you setup.



              Try:



              class BlurImageView: UIImageView {

              override func awakeFromNib() {
              super.awakeFromNib()
              }

              override init() {
              var blur:UIBlurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light)
              var effectView:UIVisualEffectView = UIVisualEffectView (effect: blur)
              effectView.frame = frame
              addSubview(effectView)
              }
              }





              share|improve this answer




























                5














                You don't need it. The reason why you're not seeing results is because you're attempting to initialize the class from a different initializer than the one you setup.



                Try:



                class BlurImageView: UIImageView {

                override func awakeFromNib() {
                super.awakeFromNib()
                }

                override init() {
                var blur:UIBlurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light)
                var effectView:UIVisualEffectView = UIVisualEffectView (effect: blur)
                effectView.frame = frame
                addSubview(effectView)
                }
                }





                share|improve this answer


























                  5












                  5








                  5







                  You don't need it. The reason why you're not seeing results is because you're attempting to initialize the class from a different initializer than the one you setup.



                  Try:



                  class BlurImageView: UIImageView {

                  override func awakeFromNib() {
                  super.awakeFromNib()
                  }

                  override init() {
                  var blur:UIBlurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light)
                  var effectView:UIVisualEffectView = UIVisualEffectView (effect: blur)
                  effectView.frame = frame
                  addSubview(effectView)
                  }
                  }





                  share|improve this answer













                  You don't need it. The reason why you're not seeing results is because you're attempting to initialize the class from a different initializer than the one you setup.



                  Try:



                  class BlurImageView: UIImageView {

                  override func awakeFromNib() {
                  super.awakeFromNib()
                  }

                  override init() {
                  var blur:UIBlurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light)
                  var effectView:UIVisualEffectView = UIVisualEffectView (effect: blur)
                  effectView.frame = frame
                  addSubview(effectView)
                  }
                  }






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 14 '14 at 20:51









                  jakenbergjakenberg

                  1,8041535




                  1,8041535






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f25317292%2fios-blur-effect-to-imageview-with-swift%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Wiesbaden

                      Marschland

                      Dieringhausen