Tusker/Tusker/Views/ComposeMediaView.swift

58 lines
1.6 KiB
Swift
Raw Normal View History

2018-08-31 02:30:19 +00:00
//
// ComposeAttachmentView.swift
// Tusker
//
// Created by Shadowfacts on 8/30/18.
// Copyright © 2018 Shadowfacts. All rights reserved.
//
import UIKit
2018-08-31 16:39:39 +00:00
protocol ComposeMediaViewDelegate {
func editDescription(for media: ComposeMediaView)
}
2018-08-31 02:30:19 +00:00
class ComposeMediaView: UIImageView {
2018-08-31 16:39:39 +00:00
var delegate: ComposeMediaViewDelegate?
2018-08-31 02:30:19 +00:00
var remove: UIImageView
2018-08-31 16:39:39 +00:00
var mediaDescription: String?
2018-08-31 02:30:19 +00:00
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
2018-08-31 16:39:39 +00:00
addGestureRecognizer(UILongPressGestureRecognizer(target: self, action: #selector(longPressed)))
2018-08-31 02:30:19 +00:00
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()
}
2018-08-31 16:39:39 +00:00
@objc func longPressed() {
delegate?.editDescription(for: self)
}
2018-08-31 02:30:19 +00:00
}