diff --git a/MVMCoreUI/Atoms/Buttons/Link/ExternalLink.swift b/MVMCoreUI/Atoms/Buttons/Link/ExternalLink.swift index 3f0aa5d6..b8026f99 100644 --- a/MVMCoreUI/Atoms/Buttons/Link/ExternalLink.swift +++ b/MVMCoreUI/Atoms/Buttons/Link/ExternalLink.swift @@ -10,6 +10,12 @@ import UIKit open class ExternalLink: Link { + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + + private var exportImageView: UIImageView? + //-------------------------------------------------- // MARK: - ModelMoleculeViewProtocol //-------------------------------------------------- @@ -19,55 +25,33 @@ open class ExternalLink: Link { guard let model = model as? ExternalLinkModel else { return } + exportImageView?.tintColor = model.textColor.uiColor } -} - -// MARK: - MVMCoreViewProtocol -extension ExternalLink { - public override func updateView(_ size: CGFloat) { - super.updateView(size) - } + //-------------------------------------------------- + // MARK: - MVMCoreViewProtocol + //-------------------------------------------------- public override func setupView() { super.setupView() - - let imageView = UIImageView(image: MVMCoreUIUtility.imageNamed("externalLink")) - imageView.contentMode = .scaleAspectFit - imageView.translatesAutoresizingMaskIntoConstraints = false - - addSubview(imageView) - imageView.heightAnchor.constraint(equalToConstant: round(0.8 * titleLabel!.font.pointSize)).isActive = true - imageView.widthAnchor.constraint(equalToConstant: round(0.8 * titleLabel!.font.pointSize)).isActive = true + let image = MVMCoreUIUtility.imageNamed("externalLink") + exportImageView = UIImageView(image: image?.withRenderingMode(.alwaysTemplate)) - imageView.leadingAnchor.constraint(equalTo: titleLabel!.trailingAnchor, constant: PaddingOne).isActive = true - trailingAnchor.constraint(greaterThanOrEqualTo: imageView.trailingAnchor).isActive = true + guard let exportIcon = exportImageView else { return } - imageView.bottomAnchor.constraint(equalTo: titleLabel!.lastBaselineAnchor).isActive = true + exportIcon.contentMode = .scaleAspectFit + exportIcon.translatesAutoresizingMaskIntoConstraints = false + + addSubview(exportIcon) + trailingAnchor.constraint(greaterThanOrEqualTo: exportIcon.trailingAnchor).isActive = true + + if let titleLabel = titleLabel { + let dimension = round(0.6 * titleLabel.font.pointSize) + exportIcon.heightAnchor.constraint(equalToConstant: dimension).isActive = true + exportIcon.widthAnchor.constraint(equalToConstant: dimension).isActive = true + exportIcon.leadingAnchor.constraint(equalTo: titleLabel.trailingAnchor, constant: PaddingOne).isActive = true + exportIcon.bottomAnchor.constraint(equalTo: titleLabel.lastBaselineAnchor).isActive = true + } } } - -/* - static func getTextAttachmentFrom(url: String, dimension: CGFloat, label: Label) -> NSTextAttachment { - - let dimension = round(dimension * 0.8) - - let imageAttachment = NSTextAttachment() - imageAttachment.bounds = CGRect(x: 0, y: 0, width: dimension, height: dimension) - - DispatchQueue.global(qos: .default).async { - - guard let url = URL(string: url), - let data = try? Data(contentsOf: url) - else { return } - - DispatchQueue.main.sync { - imageAttachment.image = UIImage(data: data) - label.setNeedsDisplay() - } - } - - return imageAttachment - } - */ diff --git a/MVMCoreUI/Atoms/Buttons/Link/ExternalLinkModel.swift b/MVMCoreUI/Atoms/Buttons/Link/ExternalLinkModel.swift index a7fc5211..070e501e 100644 --- a/MVMCoreUI/Atoms/Buttons/Link/ExternalLinkModel.swift +++ b/MVMCoreUI/Atoms/Buttons/Link/ExternalLinkModel.swift @@ -8,7 +8,7 @@ import UIKit -class ExternalLinkModel: LinkModel { +public class ExternalLinkModel: LinkModel { override public class var identifier: String { return "externalLink"