TCCopyableLabel 1.0.1

TCCopyableLabel 1.0.1

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Jan 2015

Maintained by Thibault Charbonnier.



  • By
  • Thibault Charbonnier

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
}];