StrikethroughLabel.m 3.4 KB

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