YCXMenu+Extension.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // YCXMenu+Extension.m
  3. // powerone
  4. //
  5. // Created by clouder on 2019/9/17.
  6. // Copyright © 2019 onecloud.ltd. All rights reserved.
  7. //
  8. #import "YCXMenu+Extension.h"
  9. @implementation YCXMenu (Extension)
  10. + (void)po_showMenuWithTarget:(id)target array:(NSArray *)array
  11. {
  12. [self po_showMenuWithTarget:target array:array location:CGRectMake(SCREENWIDTH - 75, NAV_BAR_HEIGHT - 40, 90, 30)];
  13. }
  14. + (void)po_showMenuWithTarget:(id)target array:(NSArray *)array location:(CGRect)loc
  15. {
  16. if (array.count == 0)
  17. return;
  18. NSMutableArray *menuItemArray = [NSMutableArray array];
  19. id firstObjt = array.firstObject;
  20. if ([firstObjt isKindOfClass:[YCXMenuItem class]])
  21. {
  22. menuItemArray = [array mutableCopy];;
  23. }
  24. else
  25. {
  26. for (NSInteger i = 0; i<array.count; i++)
  27. {
  28. NSDictionary *dic = array[i];
  29. UIImage *image = dic[@"image"];
  30. if ([image isKindOfClass:[NSString class]])
  31. {
  32. image = [UIImage imageNamed:dic[@"image"]];
  33. }
  34. YCXMenuItem *item = [YCXMenuItem menuItem:dic[@"name"] image:image target:target action:NSSelectorFromString(dic[@"sel"])];
  35. item.tag = i;
  36. item.showBadge = NO;
  37. item.alignment = NSTextAlignmentLeft;
  38. item.foreColor = [UIColor whiteColor];
  39. [menuItemArray addObject:item];
  40. }
  41. }
  42. [YCXMenu setTintColor:[UIColor whiteColor]];
  43. [YCXMenu setSelectedColor:[UIColor whiteColor]];
  44. [YCXMenu setHasShadow:YES];
  45. [YCXMenu setTitleFont:[MOTextTools getTheFontWithSize:14.0 AndFontName:kNormalContentFontStr]];
  46. [YCXMenu setCornerRadius:4.f];
  47. [YCXMenu setSeparatorColor:UIColorFromHex(0xf5f5f5)];
  48. [YCXMenu setMenuItemMarginY:15];
  49. [YCXMenu setArrowSize:5.0];
  50. UIWindow *window = kKeyWindow;
  51. [YCXMenu showMenuInView:window fromRect:loc menuItems:menuItemArray selected:^(NSInteger index, YCXMenuItem *item) {}];
  52. }
  53. + (void)po_showMenuWithTarget:(id)target arrayParam:(NSArray *)array location:(CGRect)loc
  54. {
  55. if (array.count == 0)
  56. return;
  57. NSMutableArray *menuItemArray = [NSMutableArray array];
  58. for (NSInteger i = 0; i<array.count; i++)
  59. {
  60. NSDictionary *dic = array[i];
  61. YCXMenuItem *item = [YCXMenuItem menuItem:dic[@"name"] image:[UIImage imageNamed:dic[@"image"]] target:target action:NSSelectorFromString(dic[@"sel"]) userInfo:dic[@"userInfo"]];
  62. item.tag = i;
  63. item.showBadge = NO;
  64. item.alignment = NSTextAlignmentLeft;
  65. item.foreColor = [UIColor whiteColor];
  66. [menuItemArray addObject:item];
  67. }
  68. [YCXMenu setTintColor:[UIColor whiteColor]];
  69. [YCXMenu setSelectedColor:[UIColor whiteColor]];
  70. [YCXMenu setHasShadow:YES];
  71. [YCXMenu setTitleFont:[MOTextTools getTheFontWithSize:14.0 AndFontName:kNormalContentFontStr]];
  72. [YCXMenu setCornerRadius:5.f];
  73. [YCXMenu setSeparatorColor:UIColorFromHex(0xf5f5f5)];
  74. [YCXMenu setMenuItemMarginY:10];
  75. [YCXMenu setArrowSize:5.0];
  76. UIWindow *window = kKeyWindow;
  77. [YCXMenu showMenuInView:window fromRect:loc menuItems:menuItemArray selected:^(NSInteger index, YCXMenuItem *item) {}];
  78. }
  79. + (void)po_showMenuWithTarget:(id)target arrayParam:(NSArray *)array location:(CGRect)loc itemWidth:(CGFloat)width
  80. {
  81. if (array.count == 0)
  82. return;
  83. NSMutableArray *menuItemArray = [NSMutableArray array];
  84. for (NSInteger i = 0; i<array.count; i++)
  85. {
  86. NSDictionary *dic = array[i];
  87. YCXMenuItem *item = [YCXMenuItem menuItem:dic[@"name"] image:[UIImage imageNamed:dic[@"image"]] target:target action:NSSelectorFromString(dic[@"sel"]) userInfo:dic[@"userInfo"]];
  88. item.tag = i;
  89. item.showBadge = NO;
  90. item.alignment = NSTextAlignmentLeft;
  91. item.foreColor = [UIColor whiteColor];
  92. [menuItemArray addObject:item];
  93. }
  94. [YCXMenu setTintColor:[UIColor whiteColor]];
  95. [YCXMenu setSelectedColor:[UIColor whiteColor]];
  96. [YCXMenu setHasShadow:YES];
  97. [YCXMenu setTitleFont:[MOTextTools getTheFontWithSize:14.0 AndFontName:kNormalContentFontStr]];
  98. [YCXMenu setCornerRadius:5.f];
  99. [YCXMenu setSeparatorColor:UIColorFromHex(0xf5f5f5)];
  100. [YCXMenu setMenuItemMarginY:10];
  101. [YCXMenu setArrowSize:5.0];
  102. UIWindow *window = kKeyWindow;
  103. [YCXMenu showMenuInView:window fromRect:loc menuItems:menuItemArray itemWidth:width selected:^(NSInteger index, YCXMenuItem *item) {}];
  104. }
  105. @end