How to have a UIPageView on top of a blur effect? - ios

I am working on an app where I want to have a UIPageView on top of a blur effect. I know how to do it with storyboard, but since I am adding it on top of another view as a subview, I don't see a way to do it. Can anyone help me with this? The code I used to create the blur effect is like this:
self.view.backgroundColor = UIColor.clear
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.light)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.view.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.view.addSubview(blurEffectView)

actually you can use this method:
self.view.insertSubview(blurView, belowSubview:pageView)
right now page view on top of a blur.

Related

UITableView blurred overlay

In my project I want to achieve a blurred background in a UITableView.
So far I already set up the overlay like this:
let blurEffect = UIBlurEffect(style: .dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.view.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.tableView.insertSubview(blurEffectView, at: 0)
Now I got the problem that the blurred overlay is on top of my table cell. See given image. The order should be like this: UITableView (which has a bg-color) - UIVisualEffectView (blurred overlay) - UITableViewCell
How can I put the overlay between the table view and it's cell? Or is there even a better solution to this?
Make your blurred view tableview's background view and it should look correct.
let blurEffect = UIBlurEffect(style: .dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.view.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.tableView.backgroundView = blurEffectView

Blur UILable text line by line

I want to blur the text of my UILabel line by line. Currently I am applying a UIBlurEffect onto the UILabel but this simply blurs the whole view (obviously).
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = view.bounds
view.addSubview(blurEffectView)
But I want to make sure, that the user can recognize the lines and even the rough structure of the text like this:
How can I achieve this?

Create custom blur UIView

I have to develop an app that uses a a blur view.
I've tried to use UIVisualEffectView with UIBlueEffect but then I realised that there are just 3 types of blur that you can choose from, without an option to customise the blur.
I need to make a blur that is something between the Light and Dark modes, but I don't know how can I create a custom blur view.
Any idea on how can I do that?
Thank you!
User below code for the blur effect
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = view.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(blurEffectView)
Also you can use below library
https://github.com/ide/UIVisualEffects

how to get a blurred effect behind my UINavigationBar

I have been trying to get an effect of having my scrollView appear under the navigationBar slightly blurred as is the case in the apple messages app. I have tried the following methods and none of them has worked:
1:
self.navigationController?.navigationBar.isTranslucent = true
2:
self.navigationController?.navigationBar.barStyle = UIBarStyle.blackTranslucent
3:
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
4:
self.navigationController?.navigationBar.backgroundColor = UIColor.clear()
I have read many posts with variations of the above methods and have tried most of them but to no avail. I thought the point of setting isTranslucent = true was to get exactly that effect. Is there something else I should be trying? Basically I just want my navigationBar to be slightly see-through.
UIVisualEffectView is what you are looking for, and well demonstrated here:
let bounds = self.navigationController?.navigationBar.bounds as CGRect!
let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .Light))
visualEffectView.frame = bounds
self.navigationController?.navigationBar.addSubview(visualEffectView)
That said, use your method 1 and 2 together should also work:
self.navigationController.navigationBar.translucent = YES;
self.navigationController.navigationBar.topItem.title = #"Contacts";
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
Here you can add this code for your navigation bar blur effect this function is perfect for you
func navigationBlurEffect() {
// Add blur view
let bounds = self.navigationController?.navigationBar.bounds as CGRect!
let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .Light))
visualEffectView.frame = bounds
visualEffectView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
//here you can choose one
self.navigationController?.navigationBar.addSubview(visualEffectView)
// Or
/*
If you find that after adding blur effect on navigationBar, navigation buttons are not visible then add below line after adding blurView code.
*/
self.navigationController?.navigationBar.sendSubviewToBack(visualEffectView)
// Here you can add visual effects to any UIView control.
// Replace custom view with navigation bar in above code to add effects to custom view.
}
//**This is only for Image Blur code
And this code you can use for Image Blur effect
func getImageBlur(image:UIImageView){
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = (image.bounds)
blurEffectView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
image.addSubview(blurEffectView)
}
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = (self.navigationController?.navigationBar.bounds)!
self.navigationController?.navigationBar.addSubview(blurEffectView)

How do I make my UIImageView be on top of the Blur Effect in Swift?

I have this camera app im working on and once the picture is taken the view gets blurred including the captured image. I would like the captured image to be on top of the blur effect so It doesnt get blurred and the user could be able to see the picture they took. How would I be able to do that? This is the code I have currently:
if !UIAccessibilityIsReduceTransparencyEnabled() {
self.view.backgroundColor = UIColor.clearColor()
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.view.bounds
blurEffectView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
self.view.addSubview(blurEffectView)
}
else {
self.view.backgroundColor = UIColor.blackColor()
}
Any views added to the effect views content view will not be blurred. Any views behind the effect view will be blurred.

Resources