> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/ios/layers-ocgs/ocg-layer-browser-i.md).

# Show or hide PDF layers on iOS

Explore the functionality of PDF OCG (Optional Content Groups) dictionary with PTPDFLayerViewController. Render and control layers in your PDF documents easily. Learn how to use this feature efficient

A PDF OCG (Optional Content Groups) dictionary represents a collection of graphic objects that can be made visible or invisible. Any graphic content of the PDF can be made optional, including page contents, XObjects, and annotations.

The [`PTPDFLayerViewController`](https://sdk.apryse.com/api/ios/Classes/PTPDFLayerViewController.html) allows you to browse OCG layers associated with the document being viewed by a [`PTPDFViewCtrl`](https://sdk.apryse.com/api/ios/Classes/PTPDFViewCtrl.html). You can selectively render layers based on their states.

![](https://4149080208-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgY6xtY9ZQd9XMpvWlGM0%2Fuploads%2Fgit-blob-17351842cf33fd96a9c9b5cc4fe9199db779eaac%2Fbda0bae9a79267bc7555d0e90ad790278903e621-1280x1280.gif?alt=media)

PDF layer browser.

*The PDF layer control is part of the Tools library, so make sure you have* [*added the Tools library to your project*](/ios/ui-customization/setup.md)*.*

## Show the OCG layer browser

To create a new PDF layer view controller instance and display it from another view controller, supply a `PTPDFViewCtrl` instance to the `PTPDFLayerViewController` designated initializer:

{% tabs %}
{% tab title="Swift" %}
{% code lineNumbers="true" %}

```swift
// Initialize layer view controller with a PTPDFViewCtrl instance.
let pdfLayerViewController = PTPDFLayerViewController(pdfViewCtrl: pdfViewCtrl)

let navigationController = UINavigationController(rootViewController: pdfLayerViewController)
if ( UIDevice.current.userInterfaceIdiom == .pad ) {
    navigationController.modalPresentationStyle = .popover
    navigationController.popoverPresentationController?.barButtonItem = layerButton
}

self.present(navigationController, animated: true, completion: nil)
```

{% endcode %}
{% endtab %}

{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

```objc
// Initialize PDF layer view controller with a PTPDFViewCtrl instance.
PTPDFLayerViewController *pdfLayerViewController = [[PTPDFLayerViewController alloc] initWithPDFViewCtrl:pdfViewCtrl];

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:pdfLayerViewController];
if ( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad ) {
    navigationController.modalPresentationStyle = UIModalPresentationPopover;
    navigationController.popoverPresentationController.barButtonItem = self.layerButton;
}

[self presentViewController:navigationController animated:YES completion:nil];
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% hint style="info" %}
**The PDF layer view controller must be pushed onto a navigation controller's stack before being shown.**
{% endhint %}

{% hint style="info" %}
**Presenting on iPads:**

The PDF layer view controller is designed to be presented in a popover on iPads. To do so, you must provide the `PTPDFLayerViewController`'s [`UIPopoverPresentationController`](https://developer.apple.com/uikit/uipopoverpresentationcontroller/) with either:

* a [`sourceRect`](https://developer.apple.com/uikit/uipopoverpresentationcontroller/1622324-sourcerect/) AND
* a [`sourceView`](https://developer.apple.com/uikit/uipopoverpresentationcontroller/1622313-sourceview/)

OR

* a [`barButtonItem`](https://developer.apple.com/uikit/uipopoverpresentationcontroller/1622314-barbuttonitem/)

as in the example above.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/ios/layers-ocgs/ocg-layer-browser-i.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
