<!--
{
  "availability" : [
    "macOS: 10.8.0 - 10.10.0"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSForm/setPreferredTextFieldWidth(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSForm(im)setPreferredTextFieldWidth:"
  },
  "title" : "setPreferredTextFieldWidth(_:)"
}
-->

# setPreferredTextFieldWidth(_:)

Sets the preferred text field width used by Auto Layout.

```
func setPreferredTextFieldWidth(_ preferredWidth: CGFloat)
```

## Parameters

`preferredWidth`

The preferred width.

## Discussion

The preferred width is reflected in the cell’s [`cellSize`](/documentation/AppKit/NSCell/cellSize), which will be large enough to accommodate the title, bezel, and a text field of width preferredTextWidth. It is also reflected in the [`intrinsicContentSize`](/documentation/AppKit/NSView/intrinsicContentSize) of the form. That is, under Auto Layout, the form will try to size itself so that the text field cell is the given width, according to the usual content size constraint priorities.

If the width is negative, the [`cellSize`](/documentation/AppKit/NSCell/cellSize) matches the historic behavior, which is that it is large enough to accommodate the title, bezel, and the current text.

The preferred width is reflected in the cell’s cellSize, which will be large enough to accommodate the title, bezel, and a text field of width [`preferredTextFieldWidth()`](/documentation/AppKit/NSForm/preferredTextFieldWidth()).

This method can aid migration to Auto Layout, and is sufficient for simple cases. However, for new apps, use [`NSTextField`](/documentation/AppKit/NSTextField) objects directly instead of `NSForm`.

The default is -1.

---

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)