external icon convenience

This commit is contained in:
Kevin G Christiano 2020-02-26 13:21:43 -05:00
parent 7d8f850e63
commit 8ff8f9aa3a
2 changed files with 27 additions and 43 deletions

View File

@ -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
}
*/

View File

@ -8,7 +8,7 @@
import UIKit
class ExternalLinkModel: LinkModel {
public class ExternalLinkModel: LinkModel {
override public class var identifier: String {
return "externalLink"