StrikethroughLabel.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // StrikethroughLabel.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-5-29.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "StrikethroughLabel.h"
  9. @implementation StrikethroughLabel
  10. - (id)initWithFrame:(CGRect)frame
  11. {
  12. self = [super initWithFrame:frame];
  13. if (self) {
  14. // Initialization code
  15. }
  16. return self;
  17. }
  18. // Only override drawRect: if you perform custom drawing.
  19. // An empty implementation adversely affects performance during animation.
  20. - (void)drawRect:(CGRect)rect
  21. {
  22. CGContextRef context = UIGraphicsGetCurrentContext();
  23. // CGRect frame = self.contentView.frame;
  24. // CGContextAddRect(context,frame);
  25. CGContextSetLineWidth(context, 0.5);
  26. CGSize sizekey = [self.text sizeWithFont:self.font constrainedToSize:self.frame.size lineBreakMode:NSLineBreakByWordWrapping];
  27. // double width = sizekey.width*1.1;
  28. //
  29. // if(width>self.frame.size.width)
  30. // width = self.frame.size.width;
  31. CGContextSetStrokeColorWithColor(context, [self.textColor CGColor]);
  32. // CGRect selrect = self.bounds;
  33. // NSTextAlignmentLeft = 0, // Visually left aligned
  34. //#if TARGET_OS_IPHONE
  35. // NSTextAlignmentCenter = 1, // Visually centered
  36. // NSTextAlignmentRight = 2, // Visually right aligned
  37. //#else /* !TARGET_OS_IPHONE */
  38. // NSTextAlignmentRight = 1, // Visually right aligned
  39. // NSTextAlignmentCenter = 2, // Visually centered
  40. //#endif
  41. // NSTextAlignmentJustified = 3, // Fully-justified. The last line in a paragraph is natural-aligned.
  42. // NSTextAlignmentNatural = 4,
  43. //
  44. switch(self.textAlignment)
  45. {
  46. case NSTextAlignmentLeft:
  47. CGContextMoveToPoint(context, 0, self.bounds.size.height/2);
  48. CGContextAddLineToPoint(context, sizekey.width, self.bounds.size.height/2);
  49. break;
  50. case NSTextAlignmentCenter:
  51. CGContextMoveToPoint(context, self.bounds.size.width/2 - (sizekey.width/2*1.15), self.bounds.size.height/2);
  52. CGContextAddLineToPoint(context, self.bounds.size.width/2 + (sizekey.width/2*1.15), self.bounds.size.height/2);
  53. break;
  54. case NSTextAlignmentRight:
  55. CGContextMoveToPoint(context, self.bounds.size.width, self.bounds.size.height/2);
  56. CGContextAddLineToPoint(context, self.bounds.size.width-sizekey.width, self.bounds.size.height/2);
  57. break;
  58. default:
  59. CGContextMoveToPoint(context, 0, self.bounds.size.height/2);
  60. CGContextAddLineToPoint(context, self.bounds.size.width, self.bounds.size.height/2);
  61. }
  62. // CGContextStrokePath(context);
  63. // CGContextMoveToPoint(context, 0.5, self.bounds.origin.y);
  64. //
  65. // CGContextAddLineToPoint(context, 0.5, self.bounds.size.height);
  66. //
  67. //
  68. // CGContextMoveToPoint(context, self.bounds.size.width-0.5, self.bounds.origin.y);
  69. //
  70. // CGContextAddLineToPoint(context, self.bounds.size.width-0.5, self.bounds.size.height);
  71. if(!self.hideline)
  72. CGContextStrokePath(context);
  73. [super drawRect:rect];
  74. }
  75. @end