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)
Related
I got UIViewController contain custom navigationbar and an UITableView
I am trying to make all the view background blur so the icons and lable and information show above blur effect
I tried this but the blur effect apply on the icons and information
this code in viewWillAppear
//Background
ChatRoomTable.backgroundColor = .clear
let backgroundImage = UIImage(named: "16.png")
let imageView = UIImageView(image: backgroundImage)
ChatRoomTable.backgroundView = imageView
ChatRoomTable.tableFooterView = UIView(frame: CGRect.zero)
ChatRoomTable.sectionIndexColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.6715271832)
let blurEffect = UIBlurEffect(style: .dark)
let blurView = UIVisualEffectView(effect: blurEffect)
blurView.frame = self.view.bounds
view.addSubview(blurView)
Update
I want background like this and every thing show above
#SemarY I got your bug you added image you at wrong place so let me give you code which will help you for your desire output.
//Background
ChatRoomTable.backgroundColor = .clear
ChatRoomTable.tableFooterView = UIView(frame: CGRect.zero)
ChatRoomTable.sectionIndexColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.6715271832)
let backgroundImage = UIImage(named: "16.png")
let imageView = UIImageView(image: backgroundImage)
imageView.frame = self.view bound
view.addSubView(imageView)
let blurEffect = UIBlurEffect(style: .dark)
let blurView = UIVisualEffectView(effect: blurEffect)
blurView.frame = self.view.bounds
view.addSubview(blurView)
self.bringSubviewToFront(ChatRoomTable)
Try adding the image to the Content View of the blurView like so blurView.contentView.addSubview(imageView)
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()
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)
}
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)
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)