|
1 |
| -COMING SOON |
| 1 | +<p align="center"> |
| 2 | + <img src="/images/animation.gif" /> |
| 3 | +</p> |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +Just add `ContextMenu` to your Podfile and `pod install`. Done! |
| 8 | + |
| 9 | +```ruby |
| 10 | +pod 'ContextMenu' |
| 11 | +``` |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +Show the menu from one of your `UIViewController`s: |
| 16 | + |
| 17 | +```swift |
| 18 | +ContextMenu.shared.show( |
| 19 | + sourceViewController: self, |
| 20 | + viewController: MyContentViewController() |
| 21 | +) |
| 22 | +``` |
| 23 | + |
| 24 | +You must provide a custom `UIViewController` to display in the menu. The only requirement is that you must set `preferredContentSize` to size your content. |
| 25 | + |
| 26 | +```swift |
| 27 | +class MyContentViewController: UIViewController { |
| 28 | + override func viewDidLoad() { |
| 29 | + super.viewDidLoad() |
| 30 | + title = "Demo" |
| 31 | + preferredContentSize = CGSize(width: 200, height: 200) |
| 32 | + } |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +<img src="/images/basic.png" /> |
| 37 | + |
| 38 | +## Customizations |
| 39 | + |
| 40 | +### Display from a Source View |
| 41 | + |
| 42 | +Animate the menu out from a button or view. `ContextMenu` will take care of layout so that your menu doesn't clip the screen. |
| 43 | + |
| 44 | +``` |
| 45 | +@IBAction func onButton(_ sender: UIButton) { |
| 46 | + ContextMenu.shared.show( |
| 47 | + sourceViewController: self, |
| 48 | + viewController: MyContentViewController(), |
| 49 | + sourceView: sender |
| 50 | + ) |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +### Container Style & Display |
| 55 | + |
| 56 | +Use `ContextMenu.Options` to change the appearance of the containing view. |
| 57 | + |
| 58 | +```swift |
| 59 | +ContextMenu.shared.show( |
| 60 | + sourceViewController: self, |
| 61 | + viewController: MenuViewController(), |
| 62 | + options: ContextMenu.Options(containerStyle: ContextMenu.ContainerStyle(backgroundColor: .blue)), |
| 63 | + sourceView: button |
| 64 | +) |
| 65 | +``` |
| 66 | + |
| 67 | +<img src="/images/blue.png" /> |
| 68 | + |
| 69 | +There's plenty more you can customize with `ContextMenu.ContainerStyle`: |
| 70 | + |
| 71 | +- `cornerRadius`: The corner radius of the menu |
| 72 | +- `shadowRadius` and `shadowOpacity`: Appearance of the container shadow |
| 73 | +- `xPadding`, `yPadding`, `edgePadding`: Padding from the source view and screen edge |
| 74 | +- `overlayColor`: The color of the background |
| 75 | +- `motionEffect`: Respond to device gyroscope changes, similar to app icons on Springboard.app. |
| 76 | + |
| 77 | +If you want more customizations, we will gladly accept a Pull Request! |
| 78 | + |
| 79 | +## Acknowledgements |
| 80 | + |
| 81 | +- Heavy inspiration from [SlackTextViewController](https://github.com/slackhq/SlackTextViewController) |
| 82 | +- Created with ❤️ by [Ryan Nystrom](https://twitter.com/_ryannystrom) |
0 commit comments