In an iPhone app, I\'d like to show information in a tableView. In each cell, the text is like: John recently listen to music abcdefg.mp3. and if neede
This solution for clickable UILabel. It isn't for select link in text. Just nice solution in my opinion for clickable UILabel like UIButton:
#import
@protocol ClickableLablelDelegate
@required
- (void)onClickLabel:(UILabel *) label;
@end
@interface ClickableLable : UILabel
@property (nonatomic, weak) id delegate;
@end
#import "ClickableLable.h"
@implementation ClickableLable
-(void)awakeFromNib
{
[super awakeFromNib];
[self setUserInteractionEnabled:YES];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self setBackgroundColor:[UIColor lightGrayColor]];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[self setBackgroundColor:[UIColor clearColor]];
if ([_delegate respondsToSelector:@selector(onClickLabel:)]) {
[_delegate onClickLabel:self];
}
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[self setBackgroundColor:[UIColor clearColor]];
}