Contents

size(withAttributes:)

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

Declaration

func size(withAttributes attrs: [NSAttributedString.Key : Any]? = nil) -> CGSize

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