All Products
Search
Document Center

Card menu

Last Updated: May 25, 2021

The card menu is used to pop up a selection menu when the user clicks a card on the client page. In iOS, beeviews:BEEPopMenuView needs to be replaced with AUCardMenu.h.

Sample images

  • Multi-line combination style

  • Press effect

  • Double lines

  • Pop-up menu + Option buttons

API description

  • AUCardMenu.h
 
  1. //
  2. // AUCardMenu.h
  3. // AntUI
  4. //
  5. @class AUMultiStyleCellView;
  6. @class AUWindow;
  7. /*!
  8. @class AUCardMenu
  9. @abstract AUWindow
  10. @discussion The pop-up menu with a mask for the other part of the screen and an arrow-like corner in the upper right of the menu.
  11. */
  12. @interface AUCardMenu : AUWindow
  13. {
  14. }
  15. /**
  16. * The AUMultiStyleCellDelegate protocol needs to be implemented for cellView to respond to clicking events.
  17. * Assign the value in your own viewcontroller. popMenuView.cellView.delegate = self
  18. */
  19. @property (nonatomic, strong) AUMultiStyleCellView *cellView;
  20. /**
  21. * The initialization method (highly recommended).
  22. *
  23. * @param data The array storage object model CellDataModel.
  24. * @param location The reference point of the arrow-like corner.
  25. * @param offset The offset of the arrow-like corner relative to the reference point.
  26. *
  27. * @return self
  28. */
  29. - (instancetype)initWithData:(NSArray *)data
  30. location:(CGPoint)location
  31. offset:(CGFloat)offset;
  32. /**
  33. * Show the pop-up menu.
  34. *
  35. * @param superView superView of PopMenuView
  36. */
  37. - (void)showPopMenu:(UIView *)superView;
  38. // Hide the pop-up menu, whose calling is also recommended in the dealloc method.
  39. - (void)hidePopMenu;
  40. // Note: If a menu is shown with animation, the menu must be hidden with animation. If a menu is shown without animation, the menu must be hidden without animation.
  41. // Show a menu with animation.
  42. - (void)showPopMenu:(UIView *)superView animation:(BOOL) isAnimation;
  43. // Hide a menu with animation.
  44. - (void)hidePopMenuWithAnimation:(BOOL)isAnimation;
  45. @end
  • AUCellDataModel.h
 
  1. //
  2. // AUCellDataModel.h
  3. // AntUI
  4. //
  5. #import <Foundation/Foundation.h>
  6. /*!
  7. @class AUMultiStyleCellView
  8. @abstract UIView
  9. @discussion The sub-view in a menu.
  10. */
  11. @interface AUCellDataModel : NSObject
  12. @property (nonatomic, strong) NSString *iconUrl;
  13. @property (nonatomic, strong) NSString *titleText;
  14. @property (nonatomic, strong) NSString *descText;
  15. @property (nonatomic, strong) NSString *checkMarkUrl; // The check mark URL.
  16. @property (nonatomic, strong) NSString *indicatorUrl; // The right arrow URL.
  17. @property (nonatomic, strong) NSArray *buttonsArray; // NSArray<NSString>
  18. @property (nonatomic, strong) NSDictionary *extendDic; // The extended field for the client.
  19. @property (nonatomic, assign) BOOL selectedState; // Whether the current model is selected. The default value is NO.
  20. @end
  • AUMultiStyleCellView.h
 
  1. //
  2. // AUMultiStyleCellView.h
  3. // AntUI
  4. //
  5. #import <UIKit/UIKit.h>
  6. #import "AUCellDataModel.h"
  7. @class AUMultiStyleCellView;
  8. @protocol AUMultiStyleCellDelegate <NSObject>
  9. @optional
  10. /**
  11. * The clicking event callback.
  12. *
  13. * @param dataModel The data model corresponding to the clicked view.
  14. * @param indexPath The index of the clicked view in CellDataModel. (If CellDataModel.buttonsArray == nil, the default value of row is −1.)
  15. */
  16. - (void)DidClickCellView:(AUCellDataModel *)dataModel ForRowAtIndexpath:(NSIndexPath *)indexPath;
  17. - (void)DidClickCellButton:(AUCellDataModel *)dataModel ForRowAtIndexpath:(NSIndexPath *)indexPath;
  18. - (void)DidClickCellView:(AUCellDataModel *)dataModel ForRowAtIndexpath:(NSIndexPath *)indexPath cellView:(AUMultiStyleCellView *)cellView;
  19. @end
  20. /**
  21. * cellView integrating multiple styles.
  22. * 1. Icon + Main title
  23. * 2. Icon + Main title + Subtitle below the main title
  24. * 3. Icon + Main title + Framed button controls in multiple lines and multiple rows
  25. */
  26. @interface AUMultiStyleCellView : UIView
  27. @property (nonatomic, weak) id<AUMultiStyleCellDelegate> delegate;
  28. @property (nonatomic, strong) NSArray *cellDataArray;
  29. // If cellDataArray is empty, this method is equal to the initWithFrame method.
  30. - (instancetype)initWithFrame:(CGRect)frame
  31. cellDataArray:(NSArray *)cellDataArray
  32. isUpward:(BOOL)isUpward;
  33. // Process the status indicating whether cellView is selected.
  34. - (void)updateSelectedState;
  35. @end

Sample code

 
  1. //
  2. // cardMenuController.m
  3. // AntUI
  4. //
  5. #import "cardMenuController.h"
  6. #import "AUCardMenu.h"
  7. #import "AUCellDataModel.h"
  8. #import "AUMultiStyleCellView.h"
  9. @interface cardMenuController ()<AUMultiStyleCellDelegate>
  10. @property (nonatomic,strong) AUCardMenu * popMenuView;
  11. @end
  12. @implementation cardMenuController
  13. - (void)viewDidLoad {
  14. [super viewDidLoad];
  15. // Do any additional setup after loading the view.
  16. self.view.backgroundColor = RGB(0xF5F5F9);
  17. UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
  18. [button setFrame:CGRectMake(0, 100, self.view.width, 100)];
  19. [button setTitle:@"弹出菜单/多行组合样式" forState:UIControlStateNormal];
  20. [button setTitleColor:RGB(0x888888) forState:UIControlStateNormal];
  21. [button addTarget:self
  22. action:@selector(handleButton:)
  23. forControlEvents:UIControlEventTouchUpInside];
  24. [button.titleLabel setTextAlignment:NSTextAlignmentLeft];
  25. [button.titleLabel setFont:[UIFont systemFontOfSize:14]];
  26. [button setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
  27. [button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  28. [self.view addSubview:button];
  29. UIButton * button2 = [UIButton buttonWithType:UIButtonTypeCustom];
  30. [button2 setFrame:CGRectMake(0, 220, self.view.width, 100)];
  31. [button2 setTitle:@"弹出菜单/按压效果" forState:UIControlStateNormal];
  32. [button2 addTarget:self
  33. action:@selector(handleButton2:)
  34. forControlEvents:UIControlEventTouchUpInside];
  35. [button2.titleLabel setTextAlignment:NSTextAlignmentLeft];
  36. [button2 setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
  37. [button2 setContentMode:UIViewContentModeLeft];
  38. [button2 setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  39. [button2 setTitleColor:RGB(0x888888) forState:UIControlStateNormal];
  40. [button2.titleLabel setFont:[UIFont systemFontOfSize:14]];
  41. [self.view addSubview:button2];
  42. UIButton * button3 = [UIButton buttonWithType:UIButtonTypeCustom];
  43. [button3 setFrame:CGRectMake(0, 320, self.view.width, 100)];
  44. [button3 setTitle:@"弹出菜单/双行" forState:UIControlStateNormal];
  45. [button3 addTarget:self
  46. action:@selector(handleButton3:)
  47. forControlEvents:UIControlEventTouchUpInside];
  48. [button3.titleLabel setTextAlignment:NSTextAlignmentLeft];
  49. [button3 setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
  50. [button3 setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  51. [button3.titleLabel setFont:[UIFont systemFontOfSize:14]];
  52. [button3 setTitleColor:RGB(0x888888) forState:UIControlStateNormal];
  53. [self.view addSubview:button3];
  54. UIButton * button4 = [UIButton buttonWithType:UIButtonTypeCustom];
  55. [button4 setFrame:CGRectMake(0, 420, self.view.width, 100)];
  56. [button4 setTitle:@"弹出菜单+选择按钮" forState:UIControlStateNormal];
  57. [button4 addTarget:self
  58. action:@selector(handleButton4:)
  59. forControlEvents:UIControlEventTouchUpInside];
  60. [button4.titleLabel setTextAlignment:NSTextAlignmentLeft];
  61. [button4 setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
  62. [button4 setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  63. [button4.titleLabel setFont:[UIFont systemFontOfSize:14]];
  64. [button4 setTitleColor:RGB(0x888888) forState:UIControlStateNormal];
  65. [self.view addSubview:button4];
  66. }
  67. - (void)handleButton4:(UIButton *)button
  68. {
  69. AUCellDataModel * model = [[AUCellDataModel alloc] init];
  70. model.iconUrl = @"APCommonUI_ForDemo.bundle/hc_popmenu_dislike.png";
  71. model.titleText = @"我不感兴趣";
  72. model.buttonsArray = @[@"过时",@"看过了",@"质量差"];
  73. model.extendDic = @{@"type":@"reject",@"cardId":@"201609261515032720200000091128291606950000902688",@"CCard":@""};
  74. AUCardMenu *tmpView=[[AUCardMenu alloc]initWithData:@[model] location:CGPointMake(button.width - 20, button.centerY) offset:13];
  75. tmpView.cellView.delegate=self;
  76. [tmpView showPopMenu:button animation:YES];
  77. self.popMenuView=tmpView;
  78. }
  79. - (void)handleButton3:(UIButton *)button
  80. {
  81. AUCellDataModel * model = [[AUCellDataModel alloc] init];
  82. model.iconUrl = @"APCommonUI_ForDemo.bundle/hc_popmenu_ignore.png";
  83. model.titleText = @"忽略";
  84. // model.buttonsArray = @[@"你好",@"口吃吗",@"我不饿",@"你好吗",@"我很好"];
  85. model.extendDic = @{@"type":@"reject",@"cardId":@"201609261515032720200000091128291606950000902688",@"CCard":@""};
  86. AUCellDataModel * model4 = [[AUCellDataModel alloc] init];
  87. model4.iconUrl = @"APCommonUI_ForDemo.bundle/hc_popmenu_reject.png";
  88. model4.titleText = @"不再接受此类消息";
  89. model4.descText = @"减少此类消息的接收";
  90. model4.extendDic = @{@"type":@"reject",@"cardId":@"201609261515032720200000091128291606950000902688",@"CCard":@""};
  91. AUCardMenu *tmpView=[[AUCardMenu alloc]initWithData:@[model,model4] location:CGPointMake(button.width - 20, button.centerY) offset:13];
  92. tmpView.cellView.delegate=self;
  93. [tmpView showPopMenu:button animation:YES];
  94. self.popMenuView=tmpView;
  95. }
  96. - (void)handleButton2:(UIButton *)button
  97. {
  98. AUCellDataModel * model = [[AUCellDataModel alloc] init];
  99. model.iconUrl = @"APCommonUI_ForDemo.bundle/hc_popmenu_ignore.png";
  100. model.titleText = @"忽略";
  101. // model.buttonsArray = @[@"你好",@"口吃吗",@"我不饿",@"你好吗",@"我很好"];
  102. model.extendDic = @{@"type":@"reject",@"cardId":@"201609261515032720200000091128291606950000902688",@"CCard":@""};
  103. AUCellDataModel * model2 = [[AUCellDataModel alloc] init];
  104. model2.iconUrl = @"APCommonUI_ForDemo.bundle/hc_popmenu_dislike.png";
  105. model2.titleText = @"我不感兴趣";
  106. model2.extendDic = @{@"type":@"reject",@"cardId":@"201609261515032720200000091128291606950000902688",@"CCard":@""};
  107. model2.highlightState = YES;
  108. AUCellDataModel * model3 = [[AUCellDataModel alloc] init];
  109. model3.iconUrl = @"APCommonUI_ForDemo.bundle/hc_popmenu_inform.png";
  110. model3.titleText = @"投诉";
  111. model3.extendDic = @{@"type":@"reject",@"cardId":@"201609261515032720200000091128291606950000902688",@"CCard":@""};
  112. AUCellDataModel * model4 = [[AUCellDataModel alloc] init];
  113. model4.iconUrl = @"APCommonUI_ForDemo.bundle/hc_popmenu_reject.png";
  114. model4.titleText = @"不再接受此类消息";
  115. model4.descText = @"减少此类消息的接收";
  116. model4.extendDic = @{@"type":@"reject",@"cardId":@"201609261515032720200000091128291606950000902688",@"CCard":@""};
  117. AUCardMenu *tmpView=[[AUCardMenu alloc]initWithData:@[model,model2,model3,model4] location:CGPointMake(button.width - 20, button.centerY) offset:13];
  118. tmpView.cellView.delegate=self;
  119. [tmpView showPopMenu:button animation:YES];
  120. self.popMenuView=tmpView;
  121. }
  122. - (void)handleButton:(UIButton *)button
  123. {
  124. AUCellDataModel * model = [[AUCellDataModel alloc] init];
  125. model.iconUrl = @"APCommonUI_ForDemo.bundle/hc_popmenu_ignore.png";
  126. model.titleText = @"忽略";
  127. // model.buttonsArray = @[@"你好",@"口吃吗",@"我不饿",@"你好吗",@"我很好"];
  128. model.extendDic = @{@"type":@"reject",@"cardId":@"201609261515032720200000091128291606950000902688",@"CCard":@""};
  129. AUCellDataModel * model2 = [[AUCellDataModel alloc] init];
  130. model2.iconUrl = @"APCommonUI_ForDemo.bundle/hc_popmenu_dislike.png";
  131. model2.titleText = @"我不感兴趣";
  132. model2.extendDic = @{@"type":@"reject",@"cardId":@"201609261515032720200000091128291606950000902688",@"CCard":@""};
  133. AUCellDataModel * model3 = [[AUCellDataModel alloc] init];
  134. model3.iconUrl = @"APCommonUI_ForDemo.bundle/hc_popmenu_inform.png";
  135. model3.titleText = @"投诉";
  136. model3.extendDic = @{@"type":@"reject",@"cardId":@"201609261515032720200000091128291606950000902688",@"CCard":@""};
  137. AUCardMenu *tmpView=[[AUCardMenu alloc]initWithData:@[model,model2,model3] location:CGPointMake(button.width - 20, button.centerY) offset:13];
  138. tmpView.cellView.delegate=self;
  139. [tmpView showPopMenu:button animation:YES];
  140. self.popMenuView=tmpView;
  141. }
  142. - (void)didReceiveMemoryWarning {
  143. [super didReceiveMemoryWarning];
  144. // Dispose of any resources that can be recreated.
  145. }
  146. - (void)hidePopMenu
  147. {
  148. if (self.popMenuView) {
  149. [self.popMenuView hidePopMenuWithAnimation:YES];
  150. self.popMenuView.cellView.delegate = nil;
  151. self.popMenuView = nil;
  152. }
  153. }
  154. #pragma mark --- AUMultiStyleCellDelegate
  155. /**
  156. * The clicking event callback.
  157. *
  158. * @param dataModel The data model corresponding to the tapped view.
  159. * @param indexPath The index of the tapped view in CellDataModel. (If CellDataModel.buttonsArray == nil, the default value of row is −1.)
  160. */
  161. - (void)DidClickCellView:(AUCellDataModel *)dataModel ForRowAtIndexpath:(NSIndexPath *)indexPath
  162. {
  163. [self hidePopMenu];
  164. }
  165. - (void)DidClickCellButton:(AUCellDataModel *)dataModel ForRowAtIndexpath:(NSIndexPath *)indexPath
  166. {
  167. [self hidePopMenu];
  168. }
  169. - (void)DidClickCellView:(AUCellDataModel *)dataModel ForRowAtIndexpath:(NSIndexPath *)indexPath cellView:(AUMultiStyleCellView *)cellView
  170. {
  171. [self hidePopMenu];
  172. }
  173. - (void)dealloc
  174. {
  175. self.popMenuView = nil;
  176. }
  177. /*
  178. #pragma mark - Navigation
  179. // In a storyboard-based application, you will often want to do a little preparation before navigation
  180. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  181. // Get the new view controller using [segue destinationViewController].
  182. // Pass the selected object to the new view controller.
  183. }
  184. */
  185. @end