Frame

@objc(PESDKFrame) open class Frame: NSObject

A Frame represents a unique frame, which can have multiple images for different aspect ratios. The matching image for the current aspect ratio will be used automatically. Each frame neeeds at least one image and one thumbnail image. If no thumbnail is provide, it is automatically generated.

  • The amount by which the image should be inset when this frame is applied. The inset is specified as a value relative to the smaller side of the image.

    Declaration

    Swift

    open var imageInsets = UIEdgeInsets.zero
  • The tolerance that is used to check if this frame is a good match for a certain ratio.

    Declaration

    Swift

    open let tolerance: CGFloat
  • This string is used to identify this frame. It must be unique.

    Declaration

    Swift

    open let identifier: String
  • This indicates if a Frame is dynamic. A dynamic frame is composed of other images, and therefore it can be adjusted to fit every ratio.

    Declaration

    Swift

    fileprivate(set) open var isDynamic = false
  • Returns a newly allocated FrameBuilder. Use this initializer for dynamic frames.

    Declaration

    Swift

    public init(frameBuilder: FrameBuilder, relativeScale: CGFloat, thumbnailURL: URL, identifier: String)

    Parameters

    frameBuilder

    The builder that will build the frame.

    relativeScale

    The relative scale of the frame. Relative to the shorter side of an image.

    thumbnailURL

    A URL for the thumbnail asset.

  • Returns a newly allocated FrameBuilder. Use this initializer for static frames.

    Declaration

    Swift

    public init(identifier: String, tolerance: CGFloat)
  • Adds an image for a given ratio to this frame.

    Declaration

    Swift

    open func addImage(_ imageURL: URL, thumbnailURL: URL?, forRatio ratio: CGFloat)

    Parameters

    imageURL

    The url for the frame’s full size image. This can be a file url or a remote / url.

    thumbnailURL

    The url for the frame’s thumbnail image. This can be a file url or a remote url.

    ratio

    The ratio that this image should be used for.

  • The image url for a given ratio.

    Declaration

    Swift

    open func imageURL(forRatio ratio: CGFloat) -> URL?

    Parameters

    ratio

    The ratio to get the image url for.

    Return Value

    An image url or nil.

  • The mask image url for a given ratio.

    Declaration

    Swift

    open func maskImageURL(forRatio ratio: CGFloat, withTolerance tolerance: CGFloat) -> URL?

    Parameters

    ratio

    The ratio to get the image url for.

    tolerance

    The tolerance that is used to pick the correct image based on the aspect ratio.

    Return Value

    An image url or nil.

  • Generates a frame asset for the given size, using a FrameBuilder.

    Declaration

    Swift

    open func image(forSize size: CGSize, completion: ((UIImage?) -> Void))

    Parameters

    size

    The desired size.

    Return Value

    A the generated asset.

  • This method is out to generate a thumbnail of a dynamic frame. After generation, the image is saved to the photo album.

    Declaration

    Swift

    open func saveThumbnailToCameraRoll(forSize size: CGSize)

    Parameters

    size

    The desired size.

  • The thumbnail url for a given ratio.

    Declaration

    Swift

    open func thumbnailURL(forRatio ratio: CGFloat) -> URL?

    Parameters

    ratio

    The ratio to get the thumbnail url for.

    Return Value

    A thumbnail url or nil.

  • Checks whether a frame has an image added for a given ratio.

    Declaration

    Swift

    open func hasImage(forRatio ratio: CGFloat) -> Bool

    Parameters

    ratio

    The ratio to check.

    Return Value

    true if an image for this ratio was added, false otherwise.

  • all

    The pool of frames that is available within the SDK.

    Declaration

    Swift

    open static var all: [Frame] = Frame.createDefaultFrames()
  • Creates the default frames that are shipped with the SDK.

    Declaration

    Swift

    open class func createDefaultFrames() -> [Frame]

    Return Value

    An array of frames.