Contents

PKToolPickerCustomItem

An item that represents a custom tool in the tool picker.

Declaration

class PKToolPickerCustomItem

Overview

A custom tool item represents a tool that isn’t one of the system tools. You configure details about a custom tool item yourself using PKToolPickerCustomItem.Configuration, including providing custom images to draw the body of the tool.

The following code shows how to create a tool picker with a custom tool item. This basic implementation of imageProvider retrieves an image for the tool body from an asset catalog. A full app might use a more advanced drawing implementation for the image provider, such as using UIGraphicsImageRenderer.

// Create a configuration for a custom tool item.
var config = PKToolPickerCustomItem.Configuration(identifier: "com.example.custom-tool", name: "My Tool")

// Provide a custom image for the custom tool item.
config.imageProvider = { toolItem in
    guard let toolImage = UIImage(named: config.name) else { 
        return UIImage() 
    }
    return toolImage
}

// Configure additional appearance options for the custom tool item.
config.allowsColorSelection = true
config.defaultColor = .red
config.defaultWidth = 10.0

// Create a custom tool item using the configuration.
let customItem = PKToolPickerCustomItem(configuration: config)

// Create a picker with the custom tool item and a system ruler tool.
let items = [customItem, PKToolPickerRulerItem()]
let picker = PKToolPicker(toolItems: items)

For a more complete example of creating a custom tool item, see Configuring the PencilKit tool picker.

Topics

Creating a custom item

Configuring the custom item

Reloading the custom item image

Structures

Instance Properties

See Also

Creating a tool picker