iOS Code Snippet Make Blur Any View

Discussion in 'iOS Code Snippets' started by narek adonts, Aug 11, 2015.

  1. narek adonts

    narek adonts Well-Known Member Licensed User

    Hi,

    This small code will allow to apply a blur effect to any view.

    Code:
    Sub ApplyBlur( View as View)
    dim nome as NativeObject=Me
    nome.RunMethod(
    "MakeBlur:",Array(view))
    End sub

    #If OBJC

    -(void)MakeBlur: (UIView*)view
    {
    if (!UIAccessibilityIsReduceTransparencyEnabled()) {
        view.backgroundColor = [UIColor clearColor];

        UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
        UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
        blurEffectView.frame = view.frame;
        blurEffectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

        [view addSubview:blurEffectView];
    }
    else {
        view.backgroundColor = [UIColor blackColor];
    }
    }

    #End if
     
    ilan, susu, JanPRO and 2 others like this.
  2. narek adonts

    narek adonts Well-Known Member Licensed User

    You can also change the style:
    The exemple is with Dark style.
    There is also Light and ExtraLight
     
  3. susu

    susu Well-Known Member Licensed User

    I tried your code on iPhone 4 with iOS 7.1.2
    My app crash without any error even in Debug mode. How can I fix it? Thanks.
     
  4. narek adonts

    narek adonts Well-Known Member Licensed User

    you need iOS 8 +
     
  5. susu

    susu Well-Known Member Licensed User

    Oh, that's why. Thanks.
     
  6. ilan

    ilan Expert Licensed User

    How can we do if ios 8+ then...??
     
  7. narek adonts

    narek adonts Well-Known Member Licensed User

    Use the code in the first post ))
     
  8. ilan

    ilan Expert Licensed User

    Ok sorry i have not seen if... is...enabled...

    Thanx :)
     
    Last edited: Sep 6, 2015
  9. ilan

    ilan Expert Licensed User

    But i dont understand why susu had a crash? Have you updated the code?
     
  10. susu

    susu Well-Known Member Licensed User

    I tested on iPhone 4 with iOS 7.
     
  11. ilan

    ilan Expert Licensed User

    I think i was misunderstood, i know that you used ios 7 and i understand that it runs only from ios8+ so i asked if it is possible to add an if statement to avoid a crash

    So if app run on ios 7 do nothing only if app run on ios 8+ then do the code... to avoid crashes so i assumed he updated the code after you report a crash, but i dont see a "last edited..." in the first post :confused:
     
  12. tufanv

    tufanv Expert Licensed User

    how can we remove the blur =?
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice