Latest 1.0.1
Homepage https://github.com/thibaultCha/TCCopyableLabel
License MIT
Platforms ios 6.0, requires ARC
Authors

Provide the best UX to your users!

TCCopyableLabel is a subclass of UILabel that allows a user to copy the label’s text to the clipboard, just like a regular text input. This can be really useful in some situations where you dispplay some important real-life informations.

Demo

Inspired from Mattt Thompson‘s article about copyable labels I read in his great NSHipster book.

  • Compatible with Interface Builder.
  • Custom string to be copied in the clipboard instead of the label’s text (perform formatting to make your user’s life easier).
  • Delegate and block on copy events.
  • Press to copy duration is customizable.

Documentation :books:

Browse the documentation on Cocoadocs or add it directly to Xcode by downloading the docset and placing it into ~/Library/Developer/Shared/Documentation/DocSets/. (or use the great Dash)

Installation

Cocoapod

Add the following to your Podfile and run $ pod install:

pod 'TCCopyableLabel'

If you don’t have CocoaPods installed or integrated into your project, you can learn how to do so here.

Static files

Copy/paste TCCopyableLabel/TCCopyableLabel/TCopyableLabel.{h,m} class in your project.

Import the class:

#import "TCCopyableLabel.h"

Examples

Instanciate it as you would do with a regular UILabel:

TCCopyableLabel *copyableLabel = [[TCCopyableLabel alloc] init];
[copyableLabel setText:@"Important stuff"];

// customization stuff
[copyableLabel setMinimumPressDuration:3];
[copyableLabel setCustomString:@"Custom string to be copied"];

If you are using Interface Builder, don’t forget to add TCCopyableLabel in the class field:

Interface Builder Example

If you wish to perform something once a particular label has been copied, you can do so using the TCCopyableLabelDelegate or the copiedBlock property:

TCCopyableLabel *copiableLabel1 = [[TCCopyableLabel alloc] initWithFrame:frame delegate:self];

TCCopyableLabel *copyableLabel2 = [[TCCopyableLabel alloc] initWithFrame:frame  copiedBlock:^(NSString *copiedString) {
  // do stuff
}];

Latest podspec

{
    "name": "TCCopyableLabel",
    "version": "1.0.1",
    "summary": "UILabel that can by copied to the clipboard by the user",
    "homepage": "https://github.com/thibaultCha/TCCopyableLabel",
    "license": "MIT",
    "authors": {
        "Thibault Charbonnier": "[email protected]"
    },
    "platforms": {
        "ios": "6.0"
    },
    "source": {
        "git": "https://github.com/thibaultCha/TCCopyableLabel.git",
        "tag": "1.0.1"
    },
    "source_files": "TCCopyableLabel/TCCopyableLabel/**/*.{h,m}",
    "requires_arc": true,
    "xcconfig": {
        "OTHER_LDFLAGS": "-ObjC"
    }
}

Pin It on Pinterest

Share This