Skip to content

UIVisualEffectView() constructor ​

The UIVisualEffectView() constructor creates an effect view that displays the given effect.

Syntax ​

new UIVisualEffectView()
new UIVisualEffectView(effect)

Parameters ​

effect

Optional. An effect object, one of UIBlurEffect, UIVibrancyEffect, UIGlassEffect, and UIGlassContainerEffect, or null. When it's omitted or null, effect is null and can be set later.

Return value ​

A new UIVisualEffectView. Its size is 0 × 0 pt; give it a frame yourself or position it with Auto Layout.

On a new effect view, the defaults of a few properties inherited from UIView are:

PropertyDefaultDescription
backgroundColornullNo need to set it. The effect determines the background color
clipsToBoundsfalseChange it to true for rounded corners
isUserInteractionEnabledtrueBoth the effect view and contentView receive touches by default

Exceptions ​

TypeError

  • The argument is neither an effect object nor null: UIVisualEffectView needs a UIVisualEffect or null. Passing a style name as a string (new UIVisualEffectView('systemMaterial')) gives the same error; create the effect object with a factory method first.
  • If you subclass it with class X extends UIVisualEffectView {} and then call new X(); see Native classes.

Examples ​

js
const blur = UIBlurEffect.effectWithStyle('systemMaterial');
const panel = new UIVisualEffectView(blur);
panel.frame = new CGRect(60, 260, 240, 80);

const empty = new UIVisualEffectView();
console.log(empty.effect);

Effect: panel is a 240 × 80 pt blurred panel. The console prints null.

Corresponding iOS API ​

-[UIVisualEffectView initWithEffect:].

See also ​