Recipe: Querying Subviews
A view stores an array of its children. Retrieve the array via the subviews property. The child views are always drawn after the parent, in the order in which they appear in the subviews array. These views draw in order from back to front, and the subviews array mirrors that drawing pattern. Views that appear later in the array are drawn after views that appear earlier.
The subviews property returns just those views that are immediate children of a given view. At times, you might want to retrieve a more exhaustive list of subviews, including the children’s children. Recipe 4-2 introduces allSubviews(), a simple recursive function that returns a full list of subviews for any view. Call this function with a view’s window ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access