external icon convenience
This commit is contained in:
parent
7d8f850e63
commit
8ff8f9aa3a
@ -10,6 +10,12 @@ import UIKit
|
|||||||
|
|
||||||
|
|
||||||
open class ExternalLink: Link {
|
open class ExternalLink: Link {
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
|
private var exportImageView: UIImageView?
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - ModelMoleculeViewProtocol
|
// MARK: - ModelMoleculeViewProtocol
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -19,55 +25,33 @@ open class ExternalLink: Link {
|
|||||||
|
|
||||||
guard let model = model as? ExternalLinkModel else { return }
|
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() {
|
public override func setupView() {
|
||||||
super.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
|
let image = MVMCoreUIUtility.imageNamed("externalLink")
|
||||||
imageView.widthAnchor.constraint(equalToConstant: round(0.8 * titleLabel!.font.pointSize)).isActive = true
|
exportImageView = UIImageView(image: image?.withRenderingMode(.alwaysTemplate))
|
||||||
|
|
||||||
imageView.leadingAnchor.constraint(equalTo: titleLabel!.trailingAnchor, constant: PaddingOne).isActive = true
|
guard let exportIcon = exportImageView else { return }
|
||||||
trailingAnchor.constraint(greaterThanOrEqualTo: imageView.trailingAnchor).isActive = true
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
class ExternalLinkModel: LinkModel {
|
public class ExternalLinkModel: LinkModel {
|
||||||
|
|
||||||
override public class var identifier: String {
|
override public class var identifier: String {
|
||||||
return "externalLink"
|
return "externalLink"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user