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 ...
Get The Core iOS Developer’s Cookbook, Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.