nimati / FCAlertView

FCAlertView is a Flat Customizable AlertView for iOS (Written in Objective C)
MIT License
792 stars 145 forks source link

Blurry Background #5

Closed pjebs closed 8 years ago

pjebs commented 8 years ago

It would be nice if you can add blurry background using https://github.com/ivoleko/ILTranslucentView for iOS 7 and UIVisualEffectView for iOS 8+.

The ILTranslucentView repo has objc and swift code. Unfortunately you won't be add it as a cocoapod dependency since ios7+swift+cocoapods doesn't mix and the guy put the objc files and swift files in same folder so cocoapods gets confused if you try and use only the obj files: https://github.com/ivoleko/ILTranslucentView/issues/20

@https://github.com/nimati/FCAlertView/blob/master/FCAlertView/Classes/FCAlertView.m#L36:

You can do an objective-C version of below code. (I use swift for my project)

        if #available(iOS 8.0, *) {
            // Use UIVisualEffectView
            let tvev = UIVisualEffectView(effect:  UIBlurEffect(style: .Dark))
            tvev.translatesAutoresizingMaskIntoConstraints = false
            _alertBackground.addSubview(tvev)
        } else {
            //For iOS 7 - Use ILTranslucentView
            (self.viewExternal as! ILTranslucentView).translucentAlpha = 1
            (self.viewExternal as! ILTranslucentView).translucentStyle = .Black
            (self.viewExternal as! ILTranslucentView).translucentTintColor = UIColor.clearColor()
            self.viewExternal.backgroundColor = UIColor.clearColor()
        }
nimati commented 8 years ago

Hey @pjebs ,

Thanks for pointing this out as well! This is something I'm looking to do some testing on and release in the next release. Keep me posted if you find any other resources that would be helpful.

Cheers

pjebs commented 8 years ago

I've used that library for a while. works well.

nimati commented 8 years ago

Nice, I'll take a look soon.

nimati commented 8 years ago

@pjebs Currently working on this. Will have a release soon for you to test.

pjebs commented 8 years ago

Remember to do your iOS 8 check like this:

if (NSClassFromString(@"UIVisualEffectView") != nil) {
 //iOS 8+
} else {
//iOS 7
}

rather than [UIVisualEffectView class]

nimati commented 8 years ago

Nice, will add the check.

nimati commented 8 years ago

Not yet ready for release, but if you download the repo with latest commit, you should be able to use the following, you can create the blur background effect. Let me know how it looks and how you feel about it. Once it's finalized, will add it to cocoapods. @pjebs

alert.blurBackground = YES;
nimati commented 8 years ago

Use 271f0a5

pjebs commented 8 years ago

As the code currently is, it won't be iOS 7 compatible which some people require (inc myself). The ILTranslucentView library is MIT licensed so you can add it with your repo. That would make it complete.

nimati commented 8 years ago

I see, I'll take a look at ILTranslucentView, what's your thought on the blur itself?