UILabelOutLined.m 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //
  2. // UILabelOutLined.m
  3. // XWorld
  4. //
  5. // Created by XM on 16/9/2.
  6. // Copyright © 2016年 xiongmaitech. All rights reserved.
  7. //
  8. #import "UILabelOutLined.h"
  9. @implementation UILabelOutLined
  10. -(id)initWithFrame:(CGRect)frame{
  11. self = [super initWithFrame:frame];
  12. if (self) {
  13. self.font = [UIFont systemFontOfSize:14];
  14. self.textColor = [UIColor whiteColor];
  15. self.alpha = 0.7;
  16. }
  17. return self;
  18. }
  19. - (void)drawTextInRect:(CGRect)rect {
  20. CGSize shadowOffset = self.shadowOffset;
  21. UIColor *textColor = self.textColor;
  22. CGContextRef c = UIGraphicsGetCurrentContext();
  23. CGContextSetLineWidth(c, 1);
  24. CGContextSetLineJoin(c, kCGLineJoinRound);
  25. CGContextSetTextDrawingMode(c, kCGTextStroke);
  26. self.textColor = [UIColor darkGrayColor];
  27. [super drawTextInRect:rect];
  28. CGContextSetTextDrawingMode(c, kCGTextFill);
  29. self.textColor = textColor;
  30. self.shadowOffset = CGSizeMake(0, 0);
  31. [super drawTextInRect:rect];
  32. self.shadowOffset = shadowOffset;
  33. }
  34. @end