UIImage
Extends UIImage
to support the Action Data controls and adds convenience methods for working with image properties in a Codable
, Encodable
or Decodable
class.
Examples:
// Assign aa image from Base 64 encoded String in iOS, tvOS or watchOS
let imageString = UIImage(named: "Background.png").toString()
let image: UIImage ~= imageString
-
Defines the Image Representation Format that will be used when converting a
See moreUIImage
toString
(viatoString()
) or toData
(viatoData()
).Declaration
Swift
public enum ImageRepresentationFormat
-
Sets the
UIImage
from the given Base 64 encodedString
instance.Examples:
// Assign an image from Base 64 encoded String in iOS, tvOS or watchOS let imageString = UIImage(named: "Background.png").toString() let image: UIImage ~= imageString
Declaration
Swift
public static func ~= ( left: inout UIImage, right: String)
-
Sets the
UIImage
from the givenData
instance.Examples:
// Assign an image from Base 64 encoded Data in iOS, tvOS or watchOS let imageData = UIImage(named: "Background.png").toData() let image: UIImage ~= imageData
Declaration
Swift
public static func ~= ( left: inout UIImage, right: Data)
-
Converts the
UIImage
to aString
representation encoded in Base 64.Examples:
// Assign an image to Base 64 encoded String in iOS, tvOS or watchOS let imageString = UIImage(named: "Background.png").toString()
Declaration
Swift
public func toString(imageRepresentation: ImageRepresentationFormat = .pngRepresentation) -> String
Parameters
imageRepresentation
Determines the representation that will be used when converting the image. The default is
pngRepresentation
.Return Value
The
UIImage
in the requested representation converted to a Base 64 encoded string. -
Converts the
UIImage
to aData
representation.Examples:
// Assign an image to Base 64 encoded Data in iOS, tvOS or watchOS let imageData = UIImage(named: "Background.png").toString()
Declaration
Swift
public func toData(imageRepresentation: ImageRepresentationFormat = .pngRepresentation) -> Data?
Parameters
imageRepresentation
Determins the representation that will be used when converting the image. The default is
pngRepresentation
.Return Value
The
UIImage
in the requested representation converted to a rawData
.
-
Creates a new
UIImage
instance from a Base 64 encoded string.Examples:
// Assign an image from Base 64 encoded String in iOS, tvOS or watchOS let imageString = UIImage(named: "Background.png") let image = UIImage(fromString: imageString)
Declaration
Swift
public convenience init?(fromString value: String)
Parameters
value
A Base 64 encoded
String
representing an image.