In this example, we will show you how to use the CreativeEditor SDK’s CreativeEngine to modify strokes through the block API. Strokes can be added to any shape or text and stroke styles are varying from plain solid lines to dashes and gaps of varying lengths and can have different end caps.
Strokes#
public func supportsStroke(_ id: DesignBlockID) throws -> BoolQuery if the given block has a stroke property.
- id:: The block to query.
- Returns: trueif the block has a stroke property.
public func setStrokeEnabled(_ id: DesignBlockID, enabled: Bool) throwsEnable or disable the stroke of the given design block. Required scope: “stroke/change”
- id: The block whose stroke should be enabled or disabled.
- enabled: If- true, the stroke will be enabled.
public func isStrokeEnabled(_ id: DesignBlockID) throws -> BoolQuery if the stroke of the given design block is enabled.
- id:: The block whose stroke state should be queried.
- Returns: trueif the block’s stroke is enabled.
public func setStrokeColor(_ id: DesignBlockID, color: Color) throwsSet the stroke color of the given design block. Required scope: “stroke/change”
- id: The block whose stroke color should be set.
- color: The color to set.
public func getStrokeColor(_ id: DesignBlockID) throws -> ColorGet the stroke color of the given design block.
- id:: The block whose stroke color should be queried.
- Returns: The stroke color.
public func setStrokeWidth(_ id: DesignBlockID, width: Float) throwsSet the stroke width of the given design block. Required scope: “stroke/change”
- id: The block whose stroke width should be set.
- width: The stroke width to be set.
public func getStrokeWidth(_ id: DesignBlockID) throws -> FloatGet the stroke width of the given design block.
- id:: The block whose stroke width should be queried.
- Returns: The stroke’s width.
public func setStrokeStyle(_ id: DesignBlockID, style: StrokeStyle) throwsSet the stroke style of the given design block. Required scope: “stroke/change”
- id: The block whose stroke style should be set.
- style: The stroke style to be set.
public func getStrokeStyle(_ id: DesignBlockID) throws -> StrokeStyleGet the stroke style of the given design block.
- id:: The block whose stroke style should be queried.
- Returns: The stroke’s style.
public func setStrokePosition(_ id: DesignBlockID, position: StrokePosition) throwsSet the stroke position of the given design block. Required scope: “stroke/change”
- id: The block whose stroke position should be set.
- position: The stroke position to be set.
public func getStrokePosition(_ id: DesignBlockID) throws -> StrokePositionGet the stroke position of the given design block.
- id:: The block whose stroke position should be queried.
- Returns: The stroke position.
public func setStrokeCornerGeometry(_ id: DesignBlockID, cornerGeometry: StrokeCornerGeometry) throwsSet the stroke corner geometry of the given design block. Required scope: “stroke/change”
- id: The block whose stroke join geometry should be set.
- cornerGeometry: The stroke join geometry to be set.
public func getStrokeCornerGeometry(_ id: DesignBlockID) throws -> StrokeCornerGeometryGet the stroke corner geometry of the given design block.
- id:: The block whose stroke join geometry should be queried.
- Returns: The stroke join geometry.
Full Code#
Here’s the full code for using strokes:
// Check if block supports strokesif try engine.block.supportsStroke(block) {  // Enable the stroke  try engine.block.setStrokeEnabled(block, enabled: true)  let strokeIsEnabled = try engine.block.isStrokeEnabled(block)
  // Configure it  try engine.block.setStrokeColor(block, color: .rgba(r: 1.0, g: 0.75, b: 0.8, a: 1.0))  let strokeColor = try engine.block.getStrokeColor(block)  try engine.block.setStrokeWidth(block, width: 5)  let strokeWidth = try engine.block.getStrokeWidth(block)  try engine.block.setStrokeStyle(block, style: .dashed)  let strokeStlye = try engine.block.getStrokeStyle(block)  try engine.block.setStrokePosition(block, position: .outer)  let strokePosition = try engine.block.getStrokePosition(block)  try engine.block.setStrokeCornerGeometry(block, cornerGeometry: .round)  let strokeCornerGeometry = try engine.block.getStrokeCornerGeometry(block)}