mirror of https://github.com/oxen-io/session-ios
mirror of https://github.com/oxen-io/session-ios
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.2 KiB
49 lines
1.2 KiB
// |
|
// SRCopyableLabel.swift |
|
// |
|
// Created by Stephen Radford on 08/09/2015. |
|
// Copyright (c) 2015 Cocoon Development Ltd. All rights reserved. |
|
// |
|
|
|
import UIKit |
|
|
|
@objc class SRCopyableLabel : UILabel { |
|
|
|
override public var canBecomeFirstResponder: Bool { return true } |
|
|
|
override init(frame: CGRect) { |
|
super.init(frame: frame) |
|
initialize() |
|
} |
|
|
|
required init?(coder aDecoder: NSCoder) { |
|
super.init(coder: aDecoder) |
|
initialize() |
|
} |
|
|
|
private func initialize() { |
|
isUserInteractionEnabled = true |
|
addGestureRecognizer(UILongPressGestureRecognizer( |
|
target: self, |
|
action: #selector(showMenu(sender:)) |
|
)) |
|
} |
|
|
|
override func copy(_ sender: Any?) { |
|
UIPasteboard.general.string = text |
|
UIMenuController.shared.setMenuVisible(false, animated: true) |
|
} |
|
|
|
@objc func showMenu(sender: Any?) { |
|
becomeFirstResponder() |
|
let menu = UIMenuController.shared |
|
if !menu.isMenuVisible { |
|
menu.setTargetRect(bounds, in: self) |
|
menu.setMenuVisible(true, animated: true) |
|
} |
|
} |
|
|
|
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool { |
|
return (action == #selector(copy(_:))) |
|
} |
|
}
|
|
|