Skip to content

Instantly share code, notes, and snippets.

@mwaterfall
Created May 14, 2018 08:14
Show Gist options
  • Save mwaterfall/da3fba04a706e445a5e99ca671303600 to your computer and use it in GitHub Desktop.
Save mwaterfall/da3fba04a706e445a5e99ca671303600 to your computer and use it in GitHub Desktop.
extension ImageDescriptor where ImageReference == UIImage {
static let logo = ImageDescriptor<UIImage>(
imageReference: UIImage(named: "logo")!.withRenderingMode(.alwaysTemplate),
properties: UIImageView.Properties(
contentMode: .center,
backgroundColor: .white,
tintColor: .lightGray,
accessibilityIdentifier: "logoImage"
)
)
static let loading = ImageDescriptor<UIImage>(
imageReference: UIImage.animatedLoadingImage,
properties: UIImageView.Properties(
contentMode: .center,
backgroundColor: UIColor(white: 0.93, alpha: 1),
tintColor: .lightGray,
accessibilityIdentifier: "loadingImage"
)
)
static let failure = ImageDescriptor<UIImage>(
imageReference: UIImage(named: "loading_failure")!,
properties: UIImageView.Properties(
contentMode: .center,
backgroundColor: .red,
tintColor: .white,
accessibilityIdentifier: "failureImage"
)
)
}
extension ImageDescriptor where ImageReference == URL {
static func productImage(with productImageURL: URL) -> ImageDescriptor<URL> {
return ImageDescriptor<URL>(
imageReference: productImageURL,
properties: UIImageView.Properties(
contentMode: .scaleAspectFill,
backgroundColor: .white,
tintColor: .black,
accessibilityIdentifier: "productImage"
)
)
}
}
extension UIImage {
static let animatedLoadingImage: UIImage = {
let loadingImages = (0 ..< 10).map({ UIImage(named: "loading\($0).gif")! })
let animatedLoadingImage = UIImage.animatedImage(with: loadingImages, duration: 0.5)!
return animatedLoadingImage
}()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment