Latest 0.5.0
Homepage https://github.com/michaelpace/MSPTouchableLabel
License MIT
Platforms ios , requires ARC
Authors

build status
Coverage Status
CocoaPods
CocoaPods

MSPTouchableLabel is a UILabel subclass which provides a UITableView -like interface for creating interactive labels. It has no dependencies.

The public API of this pod may change since a 1.0.0 release hasn’t been reached. Please use caution when upgrading. Not recommended for use in production apps.

Installation

Add pod 'MSPTouchableLabel' to your Podfile and run pod install or pod update.

Usage

Most basic usage:

  • Instantiate an MSPTouchableLabel.
  • Set the label’s dataSource.
  • Implement the MSPTouchableLabelDataSource method textForTouchableLabel:.
  • Add the label to your view.

You can optionally implement MSPTouchableLabelDelegate methods to find out about interaction with the label, as shown below:


#import "MSPTouchableLabel.h"

@interface BasicUsageViewController()<MSPTouchableLabelDataSource, MSPTouchableLabelDelegate>

@property (nonatomic, strong) NSNumber* tapCount;

@end

@implementation BasicUsageViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    MSPTouchableLabel* touchableLabel = [[MSPTouchableLabel alloc] init];
    touchableLabel.dataSource = self;
    touchableLabel.delegate = self;
    touchableLabel.frame = CGRectMake(20, 20, 200, 200);
    [self.view addSubview:touchableLabel];

    self.tapCount = @0;
}

- (NSArray*)textForTouchableLabel:(MSPTouchableLabel*)touchableLabel {
    return @[@"You have ", @"tapped", @" the verb in this sentence ", self.tapCount.stringValue, @" times."];
}

- (void)touchableLabel:(MSPTouchableLabel*)touchableLabel touchesDidEndAtIndex:(NSInteger)index {
    if (index == 1) {  // index of the verb, "tapped"
        self.tapCount = @(self.tapCount.intValue + 1);
    }
}

@end

For larger examples, clone this repository and see the Examples directory. Run the project to see them in action (or glance at the .gifs at the bottom of this document).

Contributing

  1. Fork this repository and make your changes.
  2. Write a test which indicates your bug fix or feature’s intent and demonstrates that it works as expected.
  3. Send a pull request 😁. I’ll make my best effort to respond promptly.

License

MIT

See also

A few example applications:

Replace text upon tap:

replace text

Links:

links

Mad libs:

mad libs

Highlighting:

highlighting

Latest podspec

{
    "name": "MSPTouchableLabel",
    "version": "0.5.0",
    "summary": "UILabel subclass with UITableView -like data source and delegate for easy dynamic labels.",
    "description": "The MSPTouchableLabel class is a UILabel subclass which provides an interfacenfor easy interaction and updates. It offers a data source and delegate fornyou to dynamically update its contents.",
    "homepage": "https://github.com/michaelpace/MSPTouchableLabel",
    "screenshots": [
        "http://i.imgur.com/5sxXxBR.gif",
        "http://i.imgur.com/zwvMlp2.gif",
        "http://i.imgur.com/IzkJmff.gif",
        "http://i.imgur.com/vGlygCp.gif"
    ],
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Michael Pace": "[email protected]"
    },
    "platforms": {
        "ios": null
    },
    "source": {
        "git": "https://github.com/michaelpace/MSPTouchableLabel.git",
        "tag": "0.5.0"
    },
    "source_files": "Source/MSPTouchableLabel.{h,m}",
    "requires_arc": true
}

Pin It on Pinterest

Share This