How to create opaque background like in the bottom panel in Swift? - ios

I want to create label with the background color like in the bottom panel of iOS7-8, something like this:
Or create a view and inside of it put label. How can I achieve this result?

You can use blureffect
For example
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light)
let bluredEffectView = UIVisualEffectView(effect: blurEffect)
bluredEffectView.frame = CGRectMake(100, 100, 200, 200)
self.imageview.addSubview(bluredEffectView)
Screen shot

Related

I want my self.view content should be visible but blurred, propose best way

In storyBoard, I added separate UIView as First responder in view controller.Then I added that view as subview of self.view. But I want self.view should be blurred when subview is shown. How can i do this?
I tried by applying
let imageView = UIImageView(image: UIImage(named: "blur2.jpg"))
imageView.frame = self.view.bounds
imageView.contentMode = .scaleAspectFit
self.view.addSubview(imageView)
let blurEffect = UIBlurEffect(style: .regular)
let blurredEffectView = UIVisualEffectView(effect: blurEffect)
blurredEffectView.frame = imageView.bounds
self.view.addSubview(blurredEffectView)
self.view.addSubview(view_Message)
view_Message.center = self.view.center
view_Message.alpha = 1
view_Message.layer.cornerRadius = 0.3
view_Message.transform = CGAffineTransform.init(scaleX: 1.3, y: 1.3)
view_Message is UIView which is taken as FirstResponder in storyBoard.
But my self.view content goes invisible. I want My self.view should get blur(but should be shown lightly) at the same time I want my subview is shown.
i suggest you to
1. Take a UIView(let say myView) of frame self.view.bounds with clear as backgroundcolor
2. Add imageView into it of same frame
3. set backgroundcolor for imageView white,alpha nearly 0.7,and blur effect.
4. Now add your view_Message into myView as SubView.
5. Atlast add myView to self.view
or you can go by using UIVisualEffectBlur class either in storyboard or programmatically available for iOS 8+.
You can also use visualEffectView rather than blurEffect like this:
let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .light))
visualEffectView.frame = view.bounds
visualEffectView.alpha = 0.7
self.view.addSubview(visualEffectView)
You can do like this
let frame = CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height )
blurview = UIView.init(frame: frame)
blurview.backgroundColor = UIColor.blackColor()
blurview.layer.opacity = 0.5
self.view.addSubview(blurview)
Check 3D view. It seems That your ImageView is On Top Of all views. This will hide all your views behind it.
Try
self.view.sendSubviewToBack(imageView)
at the end, This will send imagview at back an your all subviews will be visible.

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

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.

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 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