Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Demo gir, init methods prototypes and README
  • Loading branch information
thibaultcha committed Apr 19, 2014
1 parent ed6df0d commit 71b4e60
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 14 deletions.
54 changes: 53 additions & 1 deletion README.md
@@ -1 +1,53 @@
# TCCopyableLabel
# TCCopyableLabel

TCCopyableLabel is a subclass of `UILabel` that allow a user to copy the label's text to the clipboard, just like a regular text input.

Inspired from [Mattt Thompson](http://mattt.me/)

- Compatibale 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)
- Long press duration is customizable.
-

## Documentation :books:

Browse the documentation on [Cocoadocs](http://cocoadocs.org/docsets/TCCopyableLabel) or add it directly to Xcode by [downloading]()) the docset and placing it into `~/Library/Developer/Shared/Documentation/DocSets/`. (or use the great [Dash](http://kapeli.com/dash))

## Installation

### Cocoapod

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

```ruby
pod 'TCCopyableLabel'
```

If you don't have CocoaPods installed or integrated into your project, you can learn how to do so [here](http://cocoapods.org).

### Static files

Copy/paste the `TCCopyableLabel` class in your project.

## Examples

Instanciate it as you would do with a regular `UILabel`:



In Interface Builder don't forget to add `TCCopyableLabel` in the class field:



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

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

## Changelog

3 changes: 2 additions & 1 deletion TCCopyableLabel/TCAppDelegate.m
Expand Up @@ -17,7 +17,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
self.window.backgroundColor = [UIColor whiteColor];

TCLabelExampleViewController *exampleVC = [[TCLabelExampleViewController alloc]
initWithNibName:@"TCLabelExampleViewController" bundle:nil];
initWithNibName:@"TCLabelExampleViewController"
bundle:nil];
[self.window setRootViewController:exampleVC];
[self.window makeKeyAndVisible];

Expand Down
41 changes: 41 additions & 0 deletions TCCopyableLabel/TCCopyableLabel/TCCopyableLabel.h
Expand Up @@ -9,12 +9,53 @@
#import <UIKit/UIKit.h>
@protocol TCCopyableLabelDelegate;

/**
`TCCopyableLabel` is a subclass of `UILabel` with optional properties to allow it
to be copied to the clipboard by a user.
*/
@interface TCCopyableLabel : UILabel

/**
Optional. A delegate that can be notified when a user copies the label.
@since 1.0
*/
@property (nonatomic, unsafe_unretained) id<TCCopyableLabelDelegate> delegate;

/**
Optional. A block to be performed when a user copies the label.
@since 1.0
*/
@property (nonatomic, copy) void (^labelCopied)(NSString *copiedString);

/**
Indicates if the label can be copied or not. If set to `NO`, the label will behave as
a standard `UILabel`
@since 1.0
*/
@property (nonatomic, assign, setter = setCopyingEnabled:, getter = isCopyingEnabled) BOOL copyingEnabled;

/**
The duration of the press event for the copy menu to appear.
@since 1.0
*/
@property (nonatomic, assign, setter = setMinimumPressDuration:) CFTimeInterval minimumPressDuration;

/**
A custom string to be copied instead of the label's `text` property. Usefull to perform some
formatting that could make the user's life easier.
@since 1.0
*/
@property (nonatomic, copy) NSString *customString;

- (instancetype)initWithFrame:(CGRect)frame delegate:(id<TCCopyableLabelDelegate>)delegate;

- (instancetype)initWithFrame:(CGRect)frame copiedBlock:(void (^)(NSString *copiedString))copiedBlock;

@end

@protocol TCCopyableLabelDelegate <NSObject>
Expand Down
Expand Up @@ -15,6 +15,7 @@ typedef NS_ENUM(NSUInteger, TCLabelSegmentValue){
};

@interface TCLabelExampleViewController : UIViewController <TCCopyableLabelDelegate>
@property (weak, nonatomic) IBOutlet TCCopyableLabel *customTextLabel;
@property (weak, nonatomic) IBOutlet TCCopyableLabel *longPressLabel;
@property (weak, nonatomic) IBOutlet UISegmentedControl *segmentedControl;
@property (weak, nonatomic) IBOutlet UITextView *textView;
Expand Down
Expand Up @@ -33,7 +33,7 @@ - (void)viewDidLoad
[super viewDidLoad];

[self.longPressLabel setMinimumPressDuration:3];
[self.longPressLabel setCustomString:@"Custom copied string"];
[self.customTextLabel setCustomString:@"Custom copied string"];

for (UIView *subview in self.view.subviews) {
if (subview.class == [TCCopyableLabel class]) {
Expand Down
24 changes: 13 additions & 11 deletions TCCopyableLabel/TCLabelViewExample/TCLabelExampleViewController.xib
@@ -1,12 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="5056" systemVersion="13C64" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment defaultVersion="1536" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="TCLabelExampleViewController">
<connections>
<outlet property="longPressLabel" destination="snm-Ai-6g5" id="z7w-Hr-M4n"/>
<outlet property="customTextLabel" destination="snm-Ai-6g5" id="nok-KV-e9K"/>
<outlet property="longPressLabel" destination="Y82-0y-9UY" id="E5H-wO-Xdk"/>
<outlet property="segmentedControl" destination="UYl-ff-T4y" id="Ykv-FY-tFH"/>
<outlet property="textView" destination="vje-1L-HWP" id="GYv-JB-3ZL"/>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
Expand All @@ -24,14 +26,14 @@
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Left custom 3s" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="snm-Ai-6g5" customClass="TCCopyableLabel">
<rect key="frame" x="0.0" y="121" width="115" height="21"/>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Custom text" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="snm-Ai-6g5" customClass="TCCopyableLabel">
<rect key="frame" x="103" y="139" width="94" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Y82-0y-9UY" customClass="TCCopyableLabel">
<rect key="frame" x="279" y="121" width="41" height="21"/>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Custom press duration" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Y82-0y-9UY" customClass="TCCopyableLabel">
<rect key="frame" x="73" y="194" width="175" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="highlightedColor"/>
Expand All @@ -45,7 +47,7 @@
</segments>
</segmentedControl>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="vje-1L-HWP">
<rect key="frame" x="40" y="171" width="240" height="99"/>
<rect key="frame" x="40" y="234" width="240" height="99"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
Expand All @@ -61,14 +63,14 @@
<constraint firstAttribute="centerX" secondItem="UYl-ff-T4y" secondAttribute="centerX" constant="-0.5" id="1J6-ww-eOg"/>
<constraint firstItem="vje-1L-HWP" firstAttribute="centerX" secondItem="xdk-EA-Xsf" secondAttribute="centerX" id="L3h-y5-qtT"/>
<constraint firstItem="xdk-EA-Xsf" firstAttribute="top" secondItem="UYl-ff-T4y" secondAttribute="bottom" constant="43" id="RPx-Wb-KVd"/>
<constraint firstItem="snm-Ai-6g5" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" id="SYt-cF-jdE"/>
<constraint firstItem="vje-1L-HWP" firstAttribute="top" secondItem="snm-Ai-6g5" secondAttribute="bottom" constant="29" id="TCR-Qa-BwF"/>
<constraint firstItem="snm-Ai-6g5" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="103" id="SYt-cF-jdE"/>
<constraint firstItem="vje-1L-HWP" firstAttribute="top" secondItem="snm-Ai-6g5" secondAttribute="bottom" constant="74" id="TCR-Qa-BwF"/>
<constraint firstItem="UYl-ff-T4y" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" constant="20" id="Uk8-HU-yNv"/>
<constraint firstItem="Y82-0y-9UY" firstAttribute="top" secondItem="xdk-EA-Xsf" secondAttribute="bottom" constant="9" id="hIY-tS-Zg9"/>
<constraint firstItem="Y82-0y-9UY" firstAttribute="top" secondItem="xdk-EA-Xsf" secondAttribute="bottom" constant="82" id="hIY-tS-Zg9"/>
<constraint firstItem="vje-1L-HWP" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="40" id="l7n-wV-I0H"/>
<constraint firstAttribute="centerX" secondItem="xdk-EA-Xsf" secondAttribute="centerX" id="svQ-Hu-58f"/>
<constraint firstAttribute="trailing" secondItem="Y82-0y-9UY" secondAttribute="trailing" id="ugu-3O-fcx"/>
<constraint firstItem="snm-Ai-6g5" firstAttribute="top" secondItem="xdk-EA-Xsf" secondAttribute="bottom" constant="9" id="uzI-9V-XN3"/>
<constraint firstAttribute="trailing" secondItem="Y82-0y-9UY" secondAttribute="trailing" constant="72" id="ugu-3O-fcx"/>
<constraint firstItem="snm-Ai-6g5" firstAttribute="top" secondItem="xdk-EA-Xsf" secondAttribute="bottom" constant="27" id="uzI-9V-XN3"/>
</constraints>
<simulatedStatusBarMetrics key="simulatedStatusBarMetrics"/>
<simulatedScreenMetrics key="simulatedDestinationMetrics" type="retina4"/>
Expand Down
Binary file added demo.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 71b4e60

Please sign in to comment.