A custom UILabel view controller for iOS with certain words tappable like Twitter (#Hashtag, @People and http://www.link.com/page)
You need only 2 files:
STTweetLabel.h
STTweetLabel.m
Don't forget to implement STLinkProtocol
and initialize the STTweetLabel
's delegate in the view controller which manages your STTweetLabel
(see the example in the project).
You can change the fonts and colors for the different words (#Hashtag/@People AND http://link.com) via the STTweetLabel
attributes.
Build and run the project in Xcode to see STTweetLabel
in action.
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 setDelegate:self];
[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];
When an user will click on a tappable word, the delegate method - (void)tweetLinkClicked:(NSString *)link
will be called. The word clicked by the user is the parameter (NSString *)link
.
Inspired by the original Twitter applications. Thanks to @TomGiana for disturbing me while I'm focused in my code!
Sebastien Thiebaud
STTweetLabel is available under the MIT license.