Latest 4.2.0
Homepage https://github.com/weby/CopyableLabel
License MIT
Platforms ios 9.0, requires ARC
Authors

UILabel extension to enable copying

Screenshot

Usage

import CopyableLabel

let label = UILabel()
label.copyable = true

Or set copyable property to true in Interface Builder.

If another object (e.g. UIViewController) has a need to know which CopyableLabel has invoked the UIMenuController (i.e. presented the ‘Copy’ balloon, register the object for CopyableLabel.didShowCopyMenuNotification notification:

NotificationCenter.default.addObserver(self, selector: #selector(receivedCopyableLabelNotification(_:)), name: CopyableLabel.didShowCopyMenuNotification, object: nil)

The registering object will receive a Notification that contains a reference to the CopyableLabel that posted the notification.

@objc func receivedCopyableLabelNotification(_ notification: NSNotification) {
    if let label = notification.object as? UILabel {
        print(label.text!)
    }
}

UIMenuController does post a UIMenuController.didShowMenuNotification, however that notification does not provide any additional information (i.e. which UI elemement posted the notification, where the menu is, etc.).

Register for the UIMenuController willHide or didHide notifications, if you need to know when the menu is dismissed.

Requirements

iOS 9 or higher

Installation

CocoaPods

CopyableLabel is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "CopyableLabel"

Carthage

You can use Carthage to install CopyableLabel by adding it to your Cartfile:

github "dostu/CopyableLabel"

Author

Donatas Stundys, [email protected]

License

CopyableLabel is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "CopyableLabel",
    "version": "4.2.0",
    "summary": "UILabel extension to enable copying",
    "description": "Copying can be enabled by setting copyable property of UILabel either in Interface Builder ornprogramatically.",
    "homepage": "https://github.com/weby/CopyableLabel",
    "screenshots": "http://i.imgur.com/7kyuTS9.png",
    "license": "MIT",
    "authors": {
        "Donatas Stundys": "[email protected]"
    },
    "source": {
        "git": "https://github.com/weby/CopyableLabel.git",
        "tag": "4.2.0"
    },
    "platforms": {
        "ios": "9.0"
    },
    "requires_arc": true,
    "source_files": "Source/*.swift"
}

Pin It on Pinterest

Share This