Instance Method

size(withAttributes:)

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

Declaration

iOS, tvOS, watchOS
func size(attributes attrs: [String : Any]? = nil) -> CGSize
macOS
func size(withAttributes attrs: [String : Any]? = nil) -> NSSize

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.