Instance Method

sizeWithAttributes:

Returns the bounding box size the receiver occupies when drawn with the given attributes.

Declaration

iOS, tvOS, watchOS
- (CGSize)sizeWithAttributes:(NSDictionary<NSAttributedStringKey, id> *)attrs;
macOS
- (NSSize)sizeWithAttributes:(NSDictionary<NSAttributedStringKey, id> *)attrs;

Parameters

attrs

A dictionary of text attributes to be applied to the string. These are the same attributes that can be applied to an NSAttributedString object, but in the case of NSString objects, the attributes apply to the entire string, rather than ranges within the string.

Return Value

The bounding box size the receiver occupies when drawn with the specified attributes.

Discussion

This method returns fractional sizes; to use a returned size to size views, you must raise its value to the nearest higher integer using the ceil function.

See Also

Sizing and Drawing Strings

drawAtPoint:withAttributes:

Draws the receiver with the font and other display characteristics of the given attributes, at the specified point in the current graphics context.

drawInRect:withAttributes:

Draws the attributed string inside the specified bounding rectangle.

drawWithRect:options:attributes:context:

Draws the attributed string in the specified bounding rectangle using the provided options.

boundingRectWithSize:options:attributes:context:

Calculates and returns the bounding rect for the receiver drawn using the given options and display characteristics, within the specified rectangle in the current graphics context.

variantFittingPresentationWidth:

Returns a string variation suitable for the specified presentation width.

NSStringDrawingOptions

Constants for the rendering options for a string when it is drawn.