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

# setAlignment(_:range:)

Sets the alignment characteristic of the paragraph style attribute for the specified range of text.

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

## Parameters

`alignment`

The alignment to use.

`range`

The range of characters.

## Discussion

When attribute fixing takes place, this change will affect only paragraphs whose first character was included in `range`. Raises an [`rangeException`](/documentation/Foundation/NSExceptionName/rangeException) if any part of `range` lies beyond the end of the receiver’s characters.

## See Also

[`-  fixParagraphStyleAttributeInRange:`](/documentation/Foundation/NSMutableAttributedString/fixParagraphStyleAttribute(in:))

Fixes the paragraph style attributes in the specified range and assigns a paragraph style to all characters in the paragraph.



---

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)