Git Product home page Git Product logo

sttweetlabel's Introduction

STTweetLabel

A custom UILabel view controller for iOS with certain words tappable like Twitter (#Hashtag, @People and http://www.link.com/page)

STTweetLabel screenshot

Documentation

You need only 2 files:

  • STTweetLabel.h
  • STTweetLabel.m

You can change the fonts and colors for the different words (#Hashtag/@People AND http://link.com) via the STTweetLabel attributes.

Demo

Build and run the project STTweetLabelExample in Xcode to see STTweetLabel in action.

Example Usage

    STTweetLabel *tweetLabel = [[STTweetLabel alloc] initWithFrame:CGRectMake(20.0, 60.0, 280.0, 200.0)];
    
    [tweetLabel setFont:[UIFont fontWithName:@"HelveticaNeue" size:17.0]];
    [tweetLabel setTextColor:[UIColor blackColor]];
    [tweetLabel setText:@"Hi. This is a new tool for @you! Developed by->@SebThiebaud for #iPhone #ObjC... ;-) My GitHub page: https://t.co/pQXDoiYA"];
    [self.view addSubview:tweetLabel];

Don't forget to implement the STLinkCallbackBlock. Without implementing the callback block, you won't be able to detect if somebody has clicked on the hashtag, user account or even a website. Blocks are easy. All you need to do is add a few lines of code:

    STLinkCallbackBlock callbackBlock = ^(STLinkActionType actionType, NSString *link) {
	        
        NSString *displayString = NULL;
        
        // determine what the user clicked on
        switch (actionType) {
                
            // if the user clicked on an account (@_max_k)    
            case STLinkActionTypeAccount:
                displayString = [NSString stringWithFormat:@"Twitter account:\n%@", link];
                break;
            
            // if the user clicked on a hashtag (#thisisreallycool)
            case STLinkActionTypeHashtag:
                displayString = [NSString stringWithFormat:@"Twitter hashtag:\n%@", link];
                break;
            
            // if the user clicked on a website (http://github.com/SebastienThiebaud)
            case STLinkActionTypeWebsite:
                displayString = [NSString stringWithFormat:@"Website:\n%@", link];
                break;
        }
        
        [_displayLabel setText:displayString];
        
    };

Once you have added those few lines of code (depending on what you want to do when the user taps on something), make sure to tell your instance of STTweetLabel to call this block:

    [_tweetLabel setCallbackBlock:callbackBlock];

Credits

Inspired by the original Twitter applications.

Thanks to

Contact

Sebastien Thiebaud

License

STTweetLabel is available under the MIT license.

sttweetlabel's People

Contributors

jjsaccolo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.