TouchLabel.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // TouchLabel.m
  3. // Apex Mobile
  4. //
  5. // Created by Ray on 14-3-5.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "TouchLabel.h"
  9. #define FONTSIZE 13
  10. #define COLOR(R,G,B,A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]
  11. @implementation TouchLabel
  12. @synthesize delegate;
  13. - (id)initWithFrame:(CGRect)frame
  14. {
  15. self = [super initWithFrame:frame];
  16. if (self) {
  17. [self setLineBreakMode:NSLineBreakByWordWrapping|NSLineBreakByTruncatingTail];
  18. // [self setFont:[UIFont systemFontOfSize:FONTSIZE]];
  19. [self setBackgroundColor:[UIColor clearColor]];
  20. [self setTextColor:COLOR(0,0,0,1.0)];
  21. [self setUserInteractionEnabled:YES];
  22. [self setNumberOfLines:0];
  23. }
  24. return self;
  25. }
  26. -(void) drawTextInRect:(CGRect)rect {
  27. return [super drawTextInRect:UIEdgeInsetsInsetRect(rect, self.insets)];
  28. }
  29. //
  30. //// 点击该label的时候, 来个高亮显示
  31. //- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  32. //// [self setTextColor:[UIColor whiteColor]];
  33. // [self setTextColor:COLOR(59,136,195,1.0)];
  34. //}
  35. //// 还原label颜色,获取手指离开屏幕时的坐标点, 在label范围内的话就可以触发自定义的操作
  36. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  37. // [self setTextColor:COLOR(0,0,0,1.0)];
  38. UITouch *touch = [touches anyObject];
  39. CGPoint points = [touch locationInView:self];
  40. 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)
  41. {
  42. [delegate touchLabel:self touchesWtihTag:self.tag];
  43. }
  44. }
  45. //-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
  46. //{
  47. // DebugLog(@"touchesMoved");
  48. //}
  49. //-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
  50. //{
  51. // DebugLog(@"touchesCancelled");
  52. // [self setTextColor:COLOR(0,0,0,1.0)];
  53. //}
  54. /*
  55. // Only override drawRect: if you perform custom drawing.
  56. // An empty implementation adversely affects performance during animation.
  57. - (void)drawRect:(CGRect)rect
  58. {
  59. // Drawing code
  60. }
  61. */
  62. @end