|
|
@@ -30,19 +30,39 @@
|
|
|
import UIKit
|
|
|
#endif
|
|
|
|
|
|
+
|
|
|
+/// Represent a placeholder type which could be set while loading as well as
|
|
|
+/// loading finished without getting an image.
|
|
|
public protocol Placeholder {
|
|
|
+
|
|
|
+ /// How the placeholder should be added to a given image view.
|
|
|
func add(to imageView: ImageView)
|
|
|
+
|
|
|
+ /// How the placeholder should be removed from a given image view.
|
|
|
func remove(from imageView: ImageView)
|
|
|
}
|
|
|
|
|
|
+/// Default implementation of an image placeholder. The image will be set or
|
|
|
+/// reset directly for `image` property of the image view.
|
|
|
extension Placeholder where Self: Image {
|
|
|
+
|
|
|
+ /// How the placeholder should be added to a given image view.
|
|
|
public func add(to imageView: ImageView) { imageView.image = self }
|
|
|
+
|
|
|
+ /// How the placeholder should be removed from a given image view.
|
|
|
public func remove(from imageView: ImageView) { imageView.image = nil }
|
|
|
}
|
|
|
|
|
|
extension Image: Placeholder {}
|
|
|
|
|
|
+/// Default implementation of an arbitrary view as placeholder. The view will be
|
|
|
+/// added as a subview when adding and be removed from its super view when removing.
|
|
|
+///
|
|
|
+/// To use your customize View type as placeholder, simply let it conforming to
|
|
|
+/// `Placeholder` by `extension MyView: Placeholder {}`.
|
|
|
extension Placeholder where Self: View {
|
|
|
+
|
|
|
+ /// How the placeholder should be added to a given image view.
|
|
|
public func add(to imageView: ImageView) {
|
|
|
imageView.addSubview(self)
|
|
|
|
|
|
@@ -55,6 +75,7 @@ extension Placeholder where Self: View {
|
|
|
])
|
|
|
}
|
|
|
|
|
|
+ /// How the placeholder should be removed from a given image view.
|
|
|
public func remove(from imageView: ImageView) {
|
|
|
self.removeFromSuperview()
|
|
|
}
|