// // TouchLabel.m // Apex Mobile // // Created by Ray on 14-3-5. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved. // #import "TouchLabel.h" #define FONTSIZE 13 #define COLOR(R,G,B,A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A] @implementation TouchLabel @synthesize delegate; - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self setLineBreakMode:NSLineBreakByWordWrapping|NSLineBreakByTruncatingTail]; // [self setFont:[UIFont systemFontOfSize:FONTSIZE]]; [self setBackgroundColor:[UIColor clearColor]]; [self setTextColor:COLOR(0,0,0,1.0)]; [self setUserInteractionEnabled:YES]; [self setNumberOfLines:0]; } return self; } -(void) drawTextInRect:(CGRect)rect { return [super drawTextInRect:UIEdgeInsetsInsetRect(rect, self.insets)]; } // //// 点击该label的时候, 来个高亮显示 //- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { //// [self setTextColor:[UIColor whiteColor]]; // [self setTextColor:COLOR(59,136,195,1.0)]; //} //// 还原label颜色,获取手指离开屏幕时的坐标点, 在label范围内的话就可以触发自定义的操作 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { // [self setTextColor:COLOR(0,0,0,1.0)]; UITouch *touch = [touches anyObject]; CGPoint points = [touch locationInView:self]; if (points.x >= self.frame.origin.x && points.y >= self.frame.origin.x && points.x <= self.frame.size.width && points.y <= self.frame.size.height) { [delegate touchLabel:self touchesWtihTag:self.tag]; } } //-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event //{ // DebugLog(@"touchesMoved"); //} //-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event //{ // DebugLog(@"touchesCancelled"); // [self setTextColor:COLOR(0,0,0,1.0)]; //} /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end