1111#import " FEPopupMenuControllerAnimatedTransitioning.h"
1212
1313static const CGFloat kDefaultContentViewWidth = 130.0 ;
14+ static const CGFloat kDefaultArrowWeight = 10.0 ;
15+ static const CGFloat kDefaultArrowHeight = 7.0 ;
1416
1517@interface FEPopupMenuController () <UITableViewDelegate,UITableViewDataSource,UIGestureRecognizerDelegate>
1618
1719@property (nonatomic , strong ) UIView *contentView;
1820@property (nonatomic , strong ) UITableView *tableView;
1921@property (nonatomic , strong ) UITapGestureRecognizer *tapBackgroundGestureRecognizer;
22+ @property (nonatomic , strong ) UIView *arrowView;
2023
2124@end
2225
@@ -30,6 +33,8 @@ -(instancetype)initWithItems:(NSArray<FEPopupMenuItem *> *)items {
3033 self.contentViewPosition = CGPointMake (0 ,0 );
3134 self.contentViewBackgroundColor = [UIColor whiteColor ];
3235 self.contentViewCornerRadius = 8.0 ;
36+ self.arrowX = self.contentViewWidth * 0.7 ;
37+ self.isShowArrow = NO ;
3338 }
3439 return self;
3540}
@@ -50,18 +55,27 @@ - (void)viewDidLoad {
5055 self.contentView = [[UIView alloc ] initWithFrame: CGRectMake (self .contentViewPosition.x,
5156 self .contentViewPosition.y,
5257 self .contentViewWidth,
53- 44 * [self .items count ])];
54- self.contentView .layer .cornerRadius = self.contentViewCornerRadius ;
55- self.contentView .clipsToBounds = YES ;
58+ 44 * [self .items count ] + kDefaultArrowHeight )];
59+
60+
61+ // arrow
62+ if (self.isShowArrow ) {
63+ self.arrowView .frame = CGRectMake (self.arrowX , 0 , self.arrowView .bounds .size .width , self.arrowView .bounds .size .height );
64+ [self .contentView addSubview: self .arrowView];
65+ }
5666
5767 // init TableView
58- self.tableView = [[UITableView alloc ] initWithFrame: self .contentView.bounds];
68+ self.tableView = [[UITableView alloc ] initWithFrame: CGRectMake (0 , kDefaultArrowHeight ,
69+ self .contentView.bounds.size.width,
70+ self .contentView.bounds.size.height - kDefaultArrowHeight )];
5971 [self .tableView registerNib: [FEPopupMenuItemCell nib ] forCellReuseIdentifier: [FEPopupMenuItemCell identifier ]];
6072 self.tableView .delegate = self;
6173 self.tableView .dataSource = self;
6274 self.tableView .separatorColor = [UIColor colorWithRed: 0.96 green: 0.96 blue: 0.96 alpha: 1 ];
6375 self.tableView .scrollEnabled = NO ;
6476 self.tableView .backgroundColor = self.contentViewBackgroundColor ;
77+ self.tableView .layer .cornerRadius = self.contentViewCornerRadius ;
78+ self.tableView .clipsToBounds = YES ;
6579
6680 if ([self .tableView respondsToSelector: @selector (setSeparatorInset: )]) {
6781 [self .tableView setSeparatorInset: UIEdgeInsetsZero];
@@ -185,4 +199,26 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceive
185199 return transitioning;
186200}
187201
202+ #pragma mark -
203+
204+ - (UIView *)arrowView {
205+ if (!_arrowView) {
206+ // draw
207+ CGSize size = CGSizeMake (kDefaultArrowWeight , kDefaultArrowHeight );
208+ UIBezierPath *path = [[UIBezierPath alloc ] init ];
209+ [path moveToPoint: CGPointMake (size.width / 2.0 , 0 )];
210+ [path addLineToPoint: CGPointMake (0 , size.height)];
211+ [path addLineToPoint: CGPointMake (size.width, size.height)];
212+ path.lineWidth = 1.0 ;
213+
214+ CAShapeLayer *arrowLayer = [CAShapeLayer layer ];
215+ arrowLayer.path = path.CGPath ;
216+
217+ _arrowView = [[UIView alloc ] initWithFrame: CGRectMake (0 , 0 , size.width, size.height)];
218+ _arrowView.layer .mask = arrowLayer;
219+ _arrowView.backgroundColor = self.contentViewBackgroundColor ;
220+ }
221+ return _arrowView;
222+ }
223+
188224@end
0 commit comments