<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UILabel/textRect(forBounds:limitedToNumberOfLines:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UILabel(im)textRectForBounds:limitedToNumberOfLines:"
  },
  "title" : "textRect(forBounds:limitedToNumberOfLines:)"
}
-->

# textRect(forBounds:limitedToNumberOfLines:)

Returns the drawing rectangle for the label’s text.

```
func textRect(forBounds bounds: CGRect, limitedToNumberOfLines numberOfLines: Int) -> CGRect
```

## Parameters

`bounds`

The bounding rectangle of the label.

`numberOfLines`

The maximum number of lines to use for the label. The value `0` indicates the label has no maximum number of lines and the rectangle should encompass all of the text.

## Return Value

The computed drawing rectangle for the label’s text.

## Discussion

Override this method in subclasses that require changes in the label’s bounding rectangle to occur before the system performs other text layout calculations. Use the value in the `numberOfLines` parameter to limit the height of the returned rectangle to the specified number of lines of text.

The system may call this method if there was a prior call to the [`sizeToFit()`](/documentation/UIKit/UIView/sizeToFit()) or [`sizeThatFits(_:)`](/documentation/UIKit/UIView/sizeThatFits(_:)) method. Note that labels in [`UITableViewCell`](/documentation/UIKit/UITableViewCell) objects have sizes based on cell dimensions, and not on a requested size.

---

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)