Skip to main content
Language:

Customize Menu Items

VideoEditor SDK supports full control over the menu items used in the editor UI.

Configure menu items#

The tool menu items displayed in the main menu can be configured through the VideoEditViewController options. The property menuItems takes an array of PhotoEditMenuItems. Here, we first create an array of MenuItems which will be converted to a PhotoEditMenuItem.

Note that items for tools not included in your license subscription will be hidden automatically.

PhotoEditMenuItem#

PhotoEditMenuItem is an enum with two possible cases:

  1. case tool(ToolMenuItem) represents a tool that can be pushed onto the stack. It has a ToolMenuItem as an associated value, which has a title, an icon and the class of the tool that should be instantiated.
  2. case action(ActionMenuItem) represents an action that should be executed when this menu item is selected. It has an ActionMenuItem as an associated value, which has a title, an icon, the closure that should be executed and which can update the current video edit model, and a state closure that is used to query the active state of the action.

The .tool case can be used to present any subclass of PhotoEditToolController, making it easier to add your very own custom tool controllers to the SDK.

File:
import UIKit
import VideoEditorSDK
class VideoCustomizeMenuItemsSwift: Example, VideoEditViewControllerDelegate {
override func invokeExample() {
// Create a `Video` from a URL to a video in the app bundle.
let video = Video(url: Bundle.main.url(forResource: "Skater", withExtension: "mp4")!)
// Create a `Configuration` object.
let configuration = Configuration { builder in
// Configure settings related to the `VideoEditViewController`.
builder.configureVideoEditViewController { options in
// Configure the available tool menu items to be displayed in the main menu.
// Menu items for tools not included in your license subscription will be hidden automatically.
options.menuItems = [
// Create the default `MenuItem`s.
ToolMenuItem.createCompositionOrTrimToolItem(),
ToolMenuItem.createAudioToolItem(),
ToolMenuItem.createTransformToolItem(),
ToolMenuItem.createFilterToolItem(),
ToolMenuItem.createAdjustToolItem(),
ToolMenuItem.createFocusToolItem(),
ToolMenuItem.createStickerToolItem(),
ToolMenuItem.createTextToolItem(),
ToolMenuItem.createTextDesignToolItem(),
ToolMenuItem.createOverlayToolItem(),
ToolMenuItem.createFrameToolItem(),
ToolMenuItem.createBrushToolItem()
].compactMap { menuItem in
// Convert `MenuItem`s to `PhotoEditMenuItem`s.
guard let menuItem = menuItem else { return nil }
return .tool(menuItem)
}.sorted { a, b in
// Sort the menu items by their title for demonstration purposes.
func title(_ menuItem: PhotoEditMenuItem) -> String {
switch menuItem {
case .tool(let menuItem):
return menuItem.title
case .action(let menuItem):
return menuItem.title
default:
return ""
}
}
return title(a) < title(b)
}
}
}
// Create and present the video editor. Make this class the delegate of it to handle export and cancelation.
let videoEditViewController = VideoEditViewController(videoAsset: video, configuration: configuration)
videoEditViewController.delegate = self
videoEditViewController.modalPresentationStyle = .fullScreen
presentingViewController?.present(videoEditViewController, animated: true, completion: nil)
}
// MARK: - VideoEditViewControllerDelegate
func videoEditViewControllerShouldStart(_ videoEditViewController: VideoEditViewController, task: VideoEditorTask) -> Bool {
// Implementing this method is optional. You can perform additional validation and interrupt the process by returning `false`.
true
}
func videoEditViewControllerDidFinish(_ videoEditViewController: VideoEditViewController, result: VideoEditorResult) {
// The user exported a new video successfully and the newly generated video is located at `result.output.url`. Dismissing the editor.
presentingViewController?.dismiss(animated: true, completion: nil)
}
func videoEditViewControllerDidFail(_ videoEditViewController: VideoEditViewController, error: VideoEditorError) {
// There was an error generating the video.
print(error.localizedDescription)
// Dismissing the editor.
presentingViewController?.dismiss(animated: true, completion: nil)
}
func videoEditViewControllerDidCancel(_ videoEditViewController: VideoEditViewController) {
// The user tapped on the cancel button within the editor. Dismissing the editor.
presentingViewController?.dismiss(animated: true, completion: nil)
}
}