Shape

public class Shape: View

Shape is a concrete subclass of View that draws a bezier path in its coordinate space.

  • C4Shape’s contents are drawn on a ShapeLayer.

    Declaration

    Swift

    public var shapeLayer: ShapeLayer
  • Initializes an empty Shape.

    Declaration

    Swift

    public override init()
  • Initializes a new Shape from a specified Path. - parameter path: A Path around which the new shape is created with the frame of the new shape fitting the path on screen.

    Declaration

    Swift

    public convenience init(_ path: Path)

    Parameters

    path

    A Path around which the new shape is created with the frame of the new shape fitting the path on screen.

  • Undocumented

    Declaration

    Swift

    public class Shape: View
  • Initializes a new Shape from the properties of another Shape. Essentially, this copies the provided shape. - parameter shape: A Shape around which the new shape is created.

    Declaration

    Swift

    public convenience init(copy original: Shape)

    Parameters

    shape

    A Shape around which the new shape is created.

  • An optional variable representing a gradient. If this is non-nil, then the shape will appear to be filled with a gradient.

    Declaration

    Swift

    public var gradientFill: Gradient?
  • The path defining the shape to be rendered. If the path extends outside the layer bounds it will not automatically be clipped to the layer. Defaults to nil. Animatable.

    Declaration

    Swift

    public var path: Path?
  • Adjusts the shape’s frame to the bounding bounding box of its specified path.

    Declaration

    Swift

    public func adjustToFitPath()
  • Returns the receiver’s frame. Animatable.

    Declaration

    Swift

    public override var frame: Rect
  • The line width used when stroking the path. Defaults to 1.0. Animatable.

    Declaration

    Swift

    public var lineWidth: Double
  • The color to stroke the path, or nil for no fill. Defaults to opaque black. Animatable.

    Declaration

    Swift

    public var strokeColor: Color?
  • The color to fill the path, or nil for no fill. Defaults to opaque black. Animatable.

    Declaration

    Swift

    public var fillColor: Color?
  • The fill rule used when filling the path. Defaults to NonZero.

    Declaration

    Swift

    public var fillRule: FillRule
  • The current rotation value of the view. Animatable. - returns: A Double value representing the cumulative rotation of the view, measured in Radians.

    Declaration

    Swift

    public override var rotation: Double

    Return Value

    A Double value representing the cumulative rotation of the view, measured in Radians.

  • This value defines the start of the path used to draw the stroked outline. The value must be in the range [0,1] with zero representing the start of the path and one the end. Values in between zero and one are interpolated linearly along the path length. Defaults to zero. Animatable.

    Declaration

    Swift

    public var strokeStart: Double
  • This value defines the end of the path used to draw the stroked outline. The value must be in the range [0,1] with zero representing the start of the path and one the end. Values in between zero and one are interpolated linearly along the path length. Defaults to 1.0. Animatable.

    Declaration

    Swift

    public var strokeEnd: Double
  • The miter limit used when stroking the path. Defaults to ten. Animatable.

    Declaration

    Swift

    public var miterLimit: Double
  • The cap style used when stroking the path. Defaults to Butt.

    Declaration

    Swift

    public var lineCap: LineCap
  • The join style used when stroking the path. Defaults to Miter.

    Declaration

    Swift

    public var lineJoin: LineJoin
  • The phase of the dashing pattern applied when creating the stroke. Defaults to zero. Animatable.

    Declaration

    Swift

    public var lineDashPhase: Double
  • The dash pattern applied when creating the stroked version of the path. Defaults to nil.

    Declaration

    Swift

    public var lineDashPattern: [NSNumber]?
  • The size of the receiver including the width of its stroke. - returns: The bounding box that surrounds the shape and its line.

    Declaration

    Swift

    public func intrinsicContentSize() -> CGSize

    Return Value

    The bounding box that surrounds the shape and its line.

  • Returns true if there is no path.

    Declaration

    Swift

    public func isEmpty() -> Bool
  • The join style for joints on the shape’s path.

    See more

    Declaration

    Swift

    public enum LineJoin
  • The cap style for the ends of the shape’s path.

    See more

    Declaration

    Swift

    public enum LineCap
  • Undocumented

    Declaration

    Swift

    public class Shape: View
  • Appends a circle to the end of the receiver’s path.

    var l = Line([Point(),Point(100,100)])
    l.addCircle(center: l.path!.currentPoint, radius: 20)
    canvas.add(l)
    

    Declaration

    Swift

    public func addCircle(center center: Point, radius: Double)

    Parameters

    center

    The center of the new circle

    radius

    The radius of the new circle

  • Appends a polygon to the end of the receiver’s path.

    var l = Line([Point(),Point(100,100)])
    var points = [Point]()
    for i in 0...10 {
        let x = random01()*100.0
        let y = random01()*100.0
        points.append(Point(x,y))
    }
    l.addPolygon(points: points, closed: true)
    canvas.add(l)
    

    Declaration

    Swift

    public func addPolygon(points points: [Point], closed: Bool = true)

    Parameters

    points

    An array of Point structs that defines the new polygon

    closed

    If true then the polygon will have an additional line between its first and last points

  • Appends a line segment to the end of the receiver’s path.

    var l = Line([Point(),Point(100,100)])
    l.addLine([Point(100,100),Point(100,0)])
    canvas.add(l)
    

    Declaration

    Swift

    public func addLine(points: [Point])

    Parameters

    points

    An array of Point structs that defines the new line

  • Appends a bezier curve to the end of the receiver’s path.

    var l = Line([Point(),Point(100,100)])
    let pts = [Point(100,100),Point(100,0)]
    let ctrls = [Point(150,100),Point(150,0)]
    l.addCurve(points: pts, controls: ctrls)
    canvas.add(l)
    

    Declaration

    Swift

    public func addCurve(points points: [Point], controls: [Point])

    Parameters

    points

    An array of Point structs that defines the beginning and end points of the curve

    controls

    An array of Point structs used to define the shape of the curve

  • Creates a flattened image of the receiver and its subviews / layers. This override takes into consideration the lineWidth of the receiver. - returns: A new Image

    Declaration

    Swift

    public override func render() -> Image?

    Return Value

    A new Image