<!--
{
  "availability" : [
    "iOS: 3.0.0 - 13.0.0",
    "iPadOS: 3.0.0 - 13.0.0",
    "macCatalyst: 13.1.0 - 13.1.0"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIMenuController/setTargetRect(_:in:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIMenuController(im)setTargetRect:inView:"
  },
  "title" : "setTargetRect(_:in:)"
}
-->

# setTargetRect(_:in:)

Sets the area in a view above or below which the editing menu is positioned.

```
func setTargetRect(_ targetRect: CGRect, in targetView: UIView)
```

## Parameters

`targetRect`

A rectangle that defines the area that is to be the target of the menu commands.

`targetView`

The view in which `targetRect` appears.

## Discussion

This target rectangle (`targetRect`) is usually the bounding rectangle of a selection. `UIMenuController` positions the editing menu above this rectangle; if there is not enough space for the menu there, it positions it below the rectangle. The menu’s pointer is placed at the center of the top or bottom of the target rectangle as appropriate. Note that if you make the width or height of the target rectangle zero, `UIMenuController` treats the target area as a line or point for positioning (for example, an insertion caret or a single point).

Once it is set, the target rectangle does not track the view; if the view moves (such as would happen in a scroll view), you must update the target rectangle accordingly.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)