Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions GLTapLabelDemo/GLTapLabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@

@property(nonatomic,assign) id<GLTapLabelDelegate> delegate;
@property(nonatomic,retain) UIColor *linkColor;
@property(nonatomic,assign) BOOL underlineLink;

@end
16 changes: 15 additions & 1 deletion GLTapLabelDemo/GLTapLabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ @implementation GLTapLabel

@synthesize delegate;
@synthesize linkColor;
@synthesize underlineLink;

-(void)drawTextInRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
UIColor *origColor = [self textColor];
[origColor set];
if(!hotFont){
Expand All @@ -47,6 +49,8 @@ -(void)drawTextInRect:(CGRect)rect
__block CGPoint drawPoint = CGPointMake(0,0);
NSString *read;
NSScanner *s = [NSScanner scannerWithString:self.text];
[s setCharactersToBeSkipped: nil];

while ([s scanUpToCharactersFromSet:[NSCharacterSet symbolCharacterSet] intoString:&read]) {
NSArray *origWords = [read componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSMutableArray *words = [NSMutableArray array];
Expand Down Expand Up @@ -74,6 +78,8 @@ -(void)drawTextInRect:(CGRect)rect
[words addObject:origWord];
}

CGContextSetStrokeColorWithColor( context, self.linkColor.CGColor );
CGContextSetLineWidth( context, 1.0 );
[words enumerateObjectsUsingBlock:^(NSString *word, NSUInteger idx, BOOL *stop) {
BOOL hot = [word hasPrefix:@"#"] || [word hasPrefix:@"@"];
UIFont *f= hot ? hotFont : self.font;
Expand All @@ -85,6 +91,11 @@ -(void)drawTextInRect:(CGRect)rect
[hotZones addObject:[NSValue valueWithCGRect:CGRectMake(drawPoint.x, drawPoint.y, s.width, s.height)]];
[hotWords addObject:word];
[linkColor set];
if ( self.underlineLink )
{
CGContextMoveToPoint( context, drawPoint.x, drawPoint.y+s.height );
CGContextAddLineToPoint( context, drawPoint.x+s.width, drawPoint.y+s.height );
}
}
[word drawAtPoint:drawPoint withFont:f];
[origColor set];
Expand All @@ -95,7 +106,8 @@ -(void)drawTextInRect:(CGRect)rect
while ([s scanCharactersFromSet:[NSCharacterSet symbolCharacterSet] intoString:&read]) {
for(int idx=0;idx<read.length;idx=idx+2)
{
NSString *word=[read substringWithRange:NSMakeRange(idx, 2)];
int charactersToRead = MIN( 2, read.length );
NSString *word=[read substringWithRange:NSMakeRange(idx, charactersToRead)];
CGSize s = [word sizeWithFont:self.font];
if(drawPoint.x + s.width > rect.size.width) {
drawPoint = CGPointMake(0, drawPoint.y + s.height);
Expand All @@ -105,6 +117,8 @@ -(void)drawTextInRect:(CGRect)rect
}
}
}
if ( self.underlineLink )
CGContextStrokePath( context );
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
Expand Down