YYTextExampleHelper.m 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 "YYKit.h"
  10. static BOOL DebugEnabled = NO;
  11. @implementation YYTextExampleHelper
  12. + (void)addDebugOptionToViewController:(UIViewController *)vc {
  13. UISwitch *switcher = [UISwitch new];
  14. switcher.layer.transformScale = 0.8;
  15. [switcher setOn:DebugEnabled];
  16. [switcher addBlockForControlEvents:UIControlEventValueChanged block:^(UISwitch *sender) {
  17. [self setDebug:sender.isOn];
  18. }];
  19. UIView *view = [UIView new];
  20. view.size = CGSizeMake(40, 44);
  21. [view addSubview:switcher];
  22. switcher.centerX = view.width / 2;
  23. switcher.centerY = view.height / 2;
  24. UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:view];
  25. vc.navigationItem.rightBarButtonItem = item;
  26. }
  27. + (void)setDebug:(BOOL)debug {
  28. YYTextDebugOption *debugOptions = [YYTextDebugOption new];
  29. if (debug) {
  30. debugOptions.baselineColor = [UIColor redColor];
  31. debugOptions.CTFrameBorderColor = [UIColor redColor];
  32. debugOptions.CTLineFillColor = [UIColor colorWithRed:0.000 green:0.463 blue:1.000 alpha:0.180];
  33. debugOptions.CGGlyphBorderColor = [UIColor colorWithRed:1.000 green:0.524 blue:0.000 alpha:0.200];
  34. } else {
  35. [debugOptions clear];
  36. }
  37. [YYTextDebugOption setSharedDebugOption:debugOptions];
  38. DebugEnabled = debug;
  39. }
  40. + (BOOL)isDebug {
  41. return DebugEnabled;
  42. }
  43. @end