refactored for the iconName image helper
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
42dccb4780
commit
8369403cbe
@ -44,7 +44,7 @@ open class Icon: View {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
/// UIImageView used to render the icon.
|
/// UIImageView used to render the icon.
|
||||||
open var imageView = UIImageView().with {
|
open var imageView = UIImageView().with {
|
||||||
$0.isAccessibilityElement = false
|
$0.isAccessibilityElement = false
|
||||||
$0.translatesAutoresizingMaskIntoConstraints = false
|
$0.translatesAutoresizingMaskIntoConstraints = false
|
||||||
$0.contentMode = .scaleAspectFill
|
$0.contentMode = .scaleAspectFill
|
||||||
$0.clipsToBounds = true
|
$0.clipsToBounds = true
|
||||||
@ -109,8 +109,8 @@ open class Icon: View {
|
|||||||
|
|
||||||
//get the image name
|
//get the image name
|
||||||
//set the image
|
//set the image
|
||||||
if let name, let image = getImage(for: name.rawValue) {
|
if let name, let image = UIImage.image(for: name, color: imageColor) {
|
||||||
setImage(image: image, imageColor: imageColor)
|
imageView.image = image
|
||||||
} else {
|
} else {
|
||||||
imageView.image = nil
|
imageView.image = nil
|
||||||
}
|
}
|
||||||
@ -129,17 +129,17 @@ open class Icon: View {
|
|||||||
super.updateAccessibility()
|
super.updateAccessibility()
|
||||||
accessibilityLabel = name?.rawValue ?? "icon"
|
accessibilityLabel = name?.rawValue ?? "icon"
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - Private Methods
|
|
||||||
//--------------------------------------------------
|
|
||||||
private func getImage(for imageName: String) -> UIImage? {
|
|
||||||
|
|
||||||
return BundleManager.shared.image(for: imageName)
|
|
||||||
}
|
|
||||||
|
|
||||||
private func setImage(image: UIImage, imageColor: UIColor) {
|
|
||||||
imageView.image = image.withTintColor(imageColor)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension UIImage {
|
||||||
|
|
||||||
|
/// UIImage helper for finding images based on the Icon.Name which uses the internal BundleManager.
|
||||||
|
/// - Parameters:
|
||||||
|
/// - name: Icon.Name rawRepresentable.
|
||||||
|
/// - color: Color to Tint the image with
|
||||||
|
/// - renderingMode: UIImage Rendering mode.
|
||||||
|
/// - Returns: UIImage for this proecess
|
||||||
|
public static func image(for iconName: Icon.Name, color: UIColor? = nil, renderingMode: UIImage.RenderingMode = .alwaysOriginal) -> UIImage? {
|
||||||
|
image(representing: iconName, color: color, renderingMode: renderingMode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user