In this example, we will show you how to use the CreativeEditor SDK’s CreativeEngine to modify a block’s blur through the block API.
Blurs can be added to any shape or page.
You can create and configure individual blurs and apply them to blocks. Blocks support at most one blur at a time. The same blur may be used for different blocks at the same time.
Creating a Blur#
To create a blur, simply use createBlur.
public func createBlur(_ type: BlurType) throws -> DesignBlockIDCreate a new blur.
type:: The type of the blur object that shall be created.- Returns: The created blur’s handle.
We currently support the following blur types:
BlurType.uniformBlurType.linearBlurType.mirroredBlurType.radial
// Create and configure a radial blurlet radialBlur = try engine.block.createBlur(.radial)Configuring a Blur#
You can configure blurs just like you configure design blocks. See Modify Properties for more detail.
try engine.block.setFloat(radialBlur, property: "radial/radius", value: 100)try engine.block.setBlur(block, blurID: radialBlur)try engine.block.setBlurEnabled(block, enabled: true)let isBlurEnabled = try engine.block.isBlurEnabled(block)Functions#
public func setBlur(_ id: DesignBlockID, blurID: DesignBlockID) throwsConnects block’s blur to the given blur block.
Required scope: “appearance/blur”
id: The block to update.blurID: A ‘blur’ block.
public func setBlurEnabled(_ id: DesignBlockID, enabled: Bool) throwsEnable or disable the blur of the given design block.
id: The block to update.enabled: The new enabled value.
public func isBlurEnabled(_ id: DesignBlockID) throws -> BoolQuery if blur is enabled for the given block.
id:: The block to query.- Returns:
true, if the blur is enabled.falseotherwise.
public func supportsBlur(_ id: DesignBlockID) throws -> BoolChecks whether the block supports blur.
id:: The block to query.- Returns:
true, if the block supports blur.
public func getBlur(_ id: DesignBlockID) throws -> DesignBlockIDGet the ‘blur’ block of the given design block.
id:: The block to query.- Returns: The ‘blur’ block.
Full Code#
Here’s the full code:
// Create and configure a radial blurlet radialBlur = try engine.block.createBlur(.radial)try engine.block.setFloat(radialBlur, property: "radial/radius", value: 100)try engine.block.setBlur(block, blurID: radialBlur)try engine.block.setBlurEnabled(block, enabled: true)let isBlurEnabled = try engine.block.isBlurEnabled(block)
// Access an existing blurif try engine.block.supportsBlur(block) { let existingBlur = try engine.block.getBlur(block)}