how to create uiview with transparent background? - swift

I saw this image in patterns.com. I try to create a modal with transparent background but it makes other contents inside uiviewcontroller to become transparent. any ideas?
As below image

Blur Effect : Swift 3
//add blur effect
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.light)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.view.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.view.addSubview(blurEffectView)
and this to delete it :
blurEffectView.removeFromSuperview()

Related

Cant get rid of grey colour behind TabBar in Swift

I put a background image to my view, so the full view should have it.
let background = UIImage(named: "background")
var imageView : UIImageView!
imageView = UIImageView(frame: view.bounds)
imageView.contentMode = UIView.ContentMode.scaleAspectFill
imageView.clipsToBounds = true
imageView.image = background
imageView.center = view.center
view.addSubview(imageView)
self.view.sendSubviewToBack(imageView)
Also I have a barTintColor for my tabBar:
tabBar.barTintColor = UIColor.blue
The problem is when my TabBar is transparent for some percent, I can see behind the grey color(probably the default color) instead of my view's background image...
Debug view hierarchy:
Try the following
UITabBar.appearance().isTranslucent = false

A Blur on an image

I tried this code on an image to blur it ... using TViOS 10.1 and Swift 3.0
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.extraLight)
let blurView = UIVisualEffectView(effect: blurEffect)
blurView.frame = CGRect(x: 256, y: 128, width: 1024, height: 512)
self.view.addSubview(blurView)
With this result... sorry this is not a blur... I am missing something here?
Your code is right, Default blur view in iOS is work like this. You want more light blur view, then you should use any third party frameworks.
I used this code in my project:
#IBOutlet var blurView: UIVisualEffectView!
override func viewDidLoad() {
super.viewDidLoad()
let blurEffect = UIBlurEffect(style: .extraDark)
self.blurView.effect = blurEffect
}
And the result is:
func blurEffect(){
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.blurView.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.blurView.addSubview(blurEffectView)
}

Aspect fill blurry view

I created some pageController which is working but with one problem. I have background image and I've added blurry view to it. But it doesn't stretch with the image:
The way I created the blurry view is this:
let blurEffect = UIBlurEffect(style: .dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.view.frame
self.view.insertSubview(blurEffectView, at: 1)
I have tried to make image to aspect fill, aspect fit etc.. Nothing works.
You have to constrain the blur effect view to the image view, just as you would with any kind of view.
Do like this:
let blurEffect = UIBlurEffect(style: .dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.view.bounds
self.view.insertSubview(blurEffectView, at: 1)

UIBlurEffect not working as expected on my UIView

I have a UIView and I set its frame in my viewDidLoad. I then use a blurBackgroundForView function to blur it:
override func viewDidLoad() {
super.viewDidLoad()
view.frame = CGRectMake(0, superView.frame.maxY-height, superView.frame.width, height)
// The view is supposed to peak in from the bottom
AnimationHelper.blurBackgroundForView(view)
}
static func blurBackgroundForView(view: UIView!){
view.backgroundColor = .clearColor()
let blurEffect = UIBlurEffect(style: .Light)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = view.frame
view.insertSubview(blurEffectView, atIndex: 0)
}
}
The issue is that the background of the UIView is NOT blurred.
When I move the function call of blurBackgroundView(view) above the view.frame = ...
I get a blurred view, but the blurred view is much to large.
The frame for blurEffectView should be CGRectMake(0, 0, superview.frame.width, height)

How to add UIVibrancyEffect to an existing UILabel ( IBOutlet )?

I have a working ViewController with working UIBlurEffect. Here is my code:
#IBOutlet weak var nameLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
let blurEffect = UIBlurEffect(style: .Light)
let blurView = UIVisualEffectView(effect: blurEffect)
blurView.frame = self.view.frame
blurView.setTranslatesAutoresizingMaskIntoConstraints(false)
self.view.insertSubview(blurView, atIndex: 0)
}
Now I would like to add a UIVibranyEffect to the nameLabel.
How to add UIVibrancyEffect programatically to an existing UILabel?
You need to instantiate an UIVisualEffectView and add whatever you want to be vibrant inside it. For example:
// Blur Effect
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = view.bounds
view.addSubview(blurEffectView)
// Vibrancy Effect
let vibrancyEffect = UIVibrancyEffect(forBlurEffect: blurEffect)
let vibrancyEffectView = UIVisualEffectView(effect: vibrancyEffect)
vibrancyEffectView.frame = view.bounds
// Label for vibrant text
let vibrantLabel = UILabel()
vibrantLabel.text = "Vibrant"
// Add label to the vibrancy view
vibrancyEffectView.contentView.addSubview(vibrantLabel)
// Add the vibrancy view to the blur view
blurEffectView.contentView.addSubview(vibrancyEffectView)