YYTextExampleHelper.m 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // YYTextExampleHelper.m
  3. // YYKitExample
  4. //
  5. // Created by ibireme on 15/9/3.
  6. // Copyright (c) 2015 ibireme. All rights reserved.
  7. //
  8. #import "YYTextExampleHelper.h"
  9. #import "YYText.h"
  10. #import "UIControl+YYAdd.h"
  11. #import "UIView+YYAdd.h"
  12. static BOOL DebugEnabled = NO;
  13. @implementation YYTextExampleHelper
  14. + (void)addDebugOptionToViewController:(UIViewController *)vc {
  15. UISwitch *switcher = [UISwitch new];
  16. [switcher.layer setValue:@(0.8) forKeyPath:@"transform.scale"];
  17. [switcher setOn:DebugEnabled];
  18. [switcher addBlockForControlEvents:UIControlEventValueChanged block:^(UISwitch *sender) {
  19. [self setDebug:sender.isOn];
  20. }];
  21. UIView *view = [UIView new];
  22. view.size = CGSizeMake(40, 44);
  23. [view addSubview:switcher];
  24. switcher.centerX = view.width / 2;
  25. switcher.centerY = view.height / 2;
  26. UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:view];
  27. vc.navigationItem.rightBarButtonItem = item;
  28. }
  29. + (void)setDebug:(BOOL)debug {
  30. YYTextDebugOption *debugOptions = [YYTextDebugOption new];
  31. if (debug) {
  32. debugOptions.baselineColor = [UIColor redColor];
  33. debugOptions.CTFrameBorderColor = [UIColor redColor];
  34. debugOptions.CTLineFillColor = [UIColor colorWithRed:0.000 green:0.463 blue:1.000 alpha:0.180];
  35. debugOptions.CGGlyphBorderColor = [UIColor colorWithRed:1.000 green:0.524 blue:0.000 alpha:0.200];
  36. } else {
  37. [debugOptions clear];
  38. }
  39. [YYTextDebugOption setSharedDebugOption:debugOptions];
  40. DebugEnabled = debug;
  41. }
  42. + (BOOL)isDebug {
  43. return DebugEnabled;
  44. }
  45. @end