@@ -53,7 +53,14 @@ extension ContextMenuDelegate {
5353
5454public var CM : ContextMenu = ContextMenu ( )
5555
56- public struct ContextMenuConstants {
56+ public class ContextMenuConstants {
57+
58+ public enum HorizontalDirection {
59+ case left
60+ case center
61+ case right
62+ }
63+
5764 public var MaxZoom : CGFloat = 1.1
5865 public var MinZoom : CGFloat = 0.8
5966 public var MenuDefaultHeight : CGFloat = 120
@@ -74,6 +81,7 @@ public struct ContextMenuConstants {
7481 public var BackgroundViewColor : UIColor = UIColor . black. withAlphaComponent ( 0.6 )
7582
7683 public var DismissOnItemTap : Bool = false
84+ public var horizontalDirection : HorizontalDirection = . left
7785}
7886
7987open class ContextMenu : NSObject {
@@ -84,7 +92,8 @@ open class ContextMenu: NSObject {
8492 open var placeHolderView : UIView ?
8593 open var headerView : UIView ?
8694 open var footerView : UIView ?
87- open var nibView : ContextMenuCell . Type = ContextMenuTextCell . self
95+ open var nibView : UINib ?
96+ open var cellClassView : ContextMenuCell . Type = ContextMenuTextCell . self
8897 open var closeAnimation = true
8998
9099 open var onItemTap : ( ( _ index: Int , _ item: ContextMenuItem ) -> Bool ) ?
@@ -301,7 +310,11 @@ open class ContextMenu: NSObject {
301310 tableView. dataSource = self
302311 tableView. delegate = self
303312 tableView. frame = menuView. bounds
304- tableView. register ( nibView, forCellReuseIdentifier: " ContextMenuCell " )
313+ if let nibView = nibView {
314+ tableView. register ( nibView, forCellReuseIdentifier: " ContextMenuCell " )
315+ } else {
316+ tableView. register ( cellClassView, forCellReuseIdentifier: " ContextMenuCell " )
317+ }
305318 tableView. tableHeaderView = self . headerView
306319 tableView. tableFooterView = self . footerView
307320 tableView. clipsToBounds = true
@@ -546,8 +559,6 @@ open class ContextMenu: NSObject {
546559 else if ( tvY + mH) > ( mainViewRect. height - MenuConstants. BottomMarginSpace) {
547560 mY = tvY - ( ( tvY + mH) - ( mainViewRect. height - MenuConstants. BottomMarginSpace) )
548561 }
549-
550-
551562 }
552563
553564 func updateVerticalTargetedImageViewRect( ) {
@@ -613,6 +624,7 @@ open class ContextMenu: NSObject {
613624 let backgroundHeight = mainViewRect. height - MenuConstants. TopMarginSpace - MenuConstants. BottomMarginSpace
614625
615626 if backgroundHeight > backgroundWidth {
627+ self . updateHorizontalDirection ( )
616628 self . updateVerticalTargetedImageViewRect ( )
617629 }
618630 else {
@@ -676,6 +688,17 @@ open class ContextMenu: NSObject {
676688 height: weakSelf. mainViewRect. height
677689 )
678690 }
691+
692+ func updateHorizontalDirection( ) {
693+ switch MenuConstants . horizontalDirection {
694+ case . left:
695+ mX = MenuConstants . MenuMarginSpace
696+ case . center:
697+ mX = ( mainViewRect. width / 2 ) - ( mW / 2 )
698+ case . right:
699+ mX = mainViewRect. width - MenuConstants. MenuMarginSpace - mW
700+ }
701+ }
679702}
680703
681704extension ContextMenu : UITableViewDataSource , UITableViewDelegate {
0 commit comments