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

# setAlignment(_:range:)

Sets the alignment of the paragraphs containing characters in the specified range.

```
func setAlignment(_ alignment: NSTextAlignment, range: NSRange)
```

## Parameters

`alignment`

The new alignment.

`range`

The range of characters whose paragraphs will have their alignment set.

## Discussion

This method does not include undo support by default. Clients must invoke [`shouldChangeText(inRanges:replacementStrings:)`](/documentation/AppKit/NSTextView/shouldChangeText(inRanges:replacementStrings:)) or [`shouldChangeText(in:replacementString:)`](/documentation/AppKit/NSTextView/shouldChangeText(in:replacementString:)) to include this method in an undoable action.

## See Also

[`var rangeForUserParagraphAttributeChange: NSRange`](/documentation/AppKit/NSTextView/rangeForUserParagraphAttributeChange)

The range of characters affected by an action method that changes paragraph (not character) attributes.



---

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)