mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-20 13:23:59 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
53
iphone/Maps/Classes/Components/CopyableLabel.swift
Normal file
53
iphone/Maps/Classes/Components/CopyableLabel.swift
Normal file
@@ -0,0 +1,53 @@
|
||||
// Label shows copy popup menu on tap or long tap.
|
||||
class CopyableLabel: UILabel {
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
self.sharedInit()
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
self.sharedInit()
|
||||
}
|
||||
|
||||
private func sharedInit() {
|
||||
self.isUserInteractionEnabled = true
|
||||
self.gestureRecognizers = [
|
||||
UILongPressGestureRecognizer(target: self, action: #selector(self.showMenu)),
|
||||
UITapGestureRecognizer(target: self, action: #selector(self.showMenu))
|
||||
]
|
||||
}
|
||||
|
||||
@objc func showMenu(_ recognizer: UILongPressGestureRecognizer) {
|
||||
self.becomeFirstResponder()
|
||||
|
||||
let menu = UIMenuController.shared
|
||||
let locationOfTouchInLabel = recognizer.location(in: self)
|
||||
|
||||
if !menu.isMenuVisible {
|
||||
var rect = bounds
|
||||
rect.origin = locationOfTouchInLabel
|
||||
rect.size = CGSize(width: 1, height: 1)
|
||||
if #available(iOS 13, *) {
|
||||
menu.showMenu(from: self, rect: rect)
|
||||
} else {
|
||||
menu.setTargetRect(rect, in: self)
|
||||
menu.setMenuVisible(true, animated: false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override func copy(_ sender: Any?) {
|
||||
UIPasteboard.general.string = text
|
||||
UIMenuController.shared.setMenuVisible(false, animated: true)
|
||||
}
|
||||
|
||||
override var canBecomeFirstResponder: Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
|
||||
return action == #selector(UIResponderStandardEditActions.copy)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user