58 lines
1.6 KiB
Swift
58 lines
1.6 KiB
Swift
//
|
|
// ComposeAttachmentView.swift
|
|
// Tusker
|
|
//
|
|
// Created by Shadowfacts on 8/30/18.
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
protocol ComposeMediaViewDelegate {
|
|
func editDescription(for media: ComposeMediaView)
|
|
}
|
|
|
|
class ComposeMediaView: UIImageView {
|
|
|
|
var delegate: ComposeMediaViewDelegate?
|
|
|
|
var remove: UIImageView
|
|
|
|
var mediaDescription: String?
|
|
|
|
required init?(coder aDecoder: NSCoder) {
|
|
return nil
|
|
}
|
|
|
|
init(image: UIImage) {
|
|
remove = UIImageView(image: UIImage(named: "Remove"))
|
|
|
|
super.init(image: image)
|
|
|
|
contentMode = .scaleAspectFill
|
|
layer.cornerRadius = 5
|
|
layer.masksToBounds = true
|
|
isUserInteractionEnabled = true
|
|
addGestureRecognizer(UILongPressGestureRecognizer(target: self, action: #selector(longPressed)))
|
|
|
|
remove.isUserInteractionEnabled = true
|
|
remove.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(removePressed)))
|
|
remove.translatesAutoresizingMaskIntoConstraints = false
|
|
addSubview(remove)
|
|
|
|
remove.widthAnchor.constraint(equalToConstant: 20).isActive = true
|
|
remove.heightAnchor.constraint(equalToConstant: 20).isActive = true
|
|
remove.topAnchor.constraint(equalTo: topAnchor, constant: 5).isActive = true
|
|
remove.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -5).isActive = true
|
|
}
|
|
|
|
@objc func removePressed() {
|
|
removeFromSuperview()
|
|
}
|
|
|
|
@objc func longPressed() {
|
|
delegate?.editDescription(for: self)
|
|
}
|
|
|
|
}
|