Frame

@available(iOS 9.0, *)
@objcMembers
@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.

Properties

  • 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
  • The default scale of the frame. This specifies the frame’s width and is relative to the shorter side of the untransformed image.

    Declaration

    Swift

    public private(set) var relativeScale: CGFloat
  • The tolerance that is used to check if this frame is a good match for a certain ratio.

    Declaration

    Swift

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

    Declaration

    Swift

    public 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

    open private(set) var isDynamic: Bool

Public API

  • Instantiates a new Frame, built using the given frame builder. 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 new Frame. Use this initializer for static frames.

    Declaration

    Swift

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

    • 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.

    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: @escaping ((UIImage?) -> Void))

    Parameters

    size

    The desired size.

    completion

    A completion block that is called with the generated asset.

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

    Declaration

    Swift

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

    Parameters

    size

    The desired size.

    relativeScale

    The width of the frame, relative to the shortest side of the untransformed image.

    completion

    A completion block that is called with the generated asset.

  • Generates a frame asset for the given ratio for a static (isDynamic == false) frame.

    Declaration

    Swift

    open func staticImage(forRatio ratio: CGFloat, completion: @escaping ((UIImage?) -> Void))

    Parameters

    ratio

    The desired ratio.

    completion

    A closure that is executed after the image has been generated.

  • This method generates 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.

Factory Methods

  • all

    The pool of frames that is available within the SDK.

    Note

    This is a wrapper for AssetCatalog.shared.

    Declaration

    Swift

    public static var all: [Frame] { get set }
  • Returns the first frame with the given identifier if available.

    Note

    This is a wrapper for AssetCatalog.shared.

    Declaration

    Swift

    public static func withIdentifier(_ identifier: String) -> Frame?

    Parameters

    identifier

    The identifier of the frame to look for.

    Return Value

    The frame with the given identifier or nil.

  • Creates the default frames that are shipped with the SDK.

    Declaration

    Swift

    @available(*, deprecated, renamed: "defaultItems")
    open class func createDefaultFrames() -> [Frame]

    Return Value

    An array of frames.

  • Creates the default frames that are shipped with the SDK.

    Declaration

    Swift

    public class var defaultItems: [Frame] { get }