Instance Method

alignmentRect(forFrame:)

Returns the view’s alignment rectangle for a given frame.

Declaration

func alignmentRect(forFrame frame: NSRect) -> NSRect

Parameters

frame

The frame whose corresponding alignment rectangle is desired.

Return Value

The alignment rectangle for the specified frame.

Discussion

The constraint-based layout system uses alignment rectangles to align views, rather than their frame. This allows custom views to be aligned based on the location of their content while still having a frame that encompasses any ornamentation they need to draw around their content, such as shadows or reflections.

The default implementation returns the view’s frame modified by the insets specified by the view’s alignmentRectInsets method. Most custom views can override alignmentRectInsets to specify the location of their content within their frame. Custom views that require arbitrary transformations can override alignmentRect(forFrame:) and frame(forAlignmentRect:) to describe the location of their content. These two methods must always be inverses of each other.

See Also

Aligning Views with Auto Layout

func frame(forAlignmentRect: NSRect) -> NSRect

Returns the view’s frame for a given alignment rectangle.

var alignmentRectInsets: NSEdgeInsets

The insets (in points) from the view’s frame that define its content rectangle.

var baselineOffsetFromBottom: CGFloat

The distance (in points) between the bottom of the view’s alignment rectangle and its baseline.

var firstBaselineOffsetFromTop: CGFloat

The distance (in points) between the top of the view’s alignment rectangle and its topmost baseline.

var lastBaselineOffsetFromBottom: CGFloat

The distance (in points) between the bottom of the view’s alignment rectangle and its bottommost baseline.