UIBarButtonItem+FLEX.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // UIBarButtonItem+FLEX.m
  3. // FLEX
  4. //
  5. // Created by Tanner on 2/4/20.
  6. // Copyright © 2020 FLEX Team. All rights reserved.
  7. //
  8. #import "UIBarButtonItem+FLEX.h"
  9. #pragma clang diagnostic ignored "-Wincomplete-implementation"
  10. @implementation UIBarButtonItem (FLEX)
  11. + (UIBarButtonItem *)flex_flexibleSpace {
  12. return [self flex_systemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
  13. }
  14. + (UIBarButtonItem *)flex_fixedSpace {
  15. UIBarButtonItem *fixed = [self flex_systemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  16. fixed.width = 60;
  17. return fixed;
  18. }
  19. + (instancetype)flex_systemItem:(UIBarButtonSystemItem)item target:(id)target action:(SEL)action {
  20. return [[self alloc] initWithBarButtonSystemItem:item target:target action:action];
  21. }
  22. + (instancetype)flex_itemWithCustomView:(UIView *)customView {
  23. return [[self alloc] initWithCustomView:customView];
  24. }
  25. + (instancetype)flex_backItemWithTitle:(NSString *)title {
  26. return [self flex_itemWithTitle:title target:nil action:nil];
  27. }
  28. + (instancetype)flex_itemWithTitle:(NSString *)title target:(id)target action:(SEL)action {
  29. return [[self alloc] initWithTitle:title style:UIBarButtonItemStylePlain target:target action:action];
  30. }
  31. + (instancetype)flex_doneStyleitemWithTitle:(NSString *)title target:(id)target action:(SEL)action {
  32. return [[self alloc] initWithTitle:title style:UIBarButtonItemStyleDone target:target action:action];
  33. }
  34. + (instancetype)flex_itemWithImage:(UIImage *)image target:(id)target action:(SEL)action {
  35. return [[self alloc] initWithImage:image style:UIBarButtonItemStylePlain target:target action:action];
  36. }
  37. + (instancetype)flex_disabledSystemItem:(UIBarButtonSystemItem)system {
  38. UIBarButtonItem *item = [self flex_systemItem:system target:nil action:nil];
  39. item.enabled = NO;
  40. return item;
  41. }
  42. + (instancetype)flex_disabledItemWithTitle:(NSString *)title style:(UIBarButtonItemStyle)style {
  43. UIBarButtonItem *item = [self flex_itemWithTitle:title target:nil action:nil];
  44. item.enabled = NO;
  45. return item;
  46. }
  47. + (instancetype)flex_disabledItemWithImage:(UIImage *)image {
  48. UIBarButtonItem *item = [self flex_itemWithImage:image target:nil action:nil];
  49. item.enabled = NO;
  50. return item;
  51. }
  52. - (UIBarButtonItem *)flex_withTintColor:(UIColor *)tint {
  53. self.tintColor = tint;
  54. return self;
  55. }
  56. @end