iOS development frame, contentsize, Contentoffset, contentinset the difference between the analysis

Source: Internet
Author: User

1. Overview

In iOS development, layout-related issues are bound to be involved, and the frame,bounds,contensize,contentoffset,contentinset of these layout-related concepts makes many beginners confused. Although it is possible to understand these concepts initially, the layout of most of the interfaces can be completed, but the layout of the more complex pages is a bit too much.

2. Conceptual Analysis 2.1 Frame

Frame is a rectangular area that reflects the position of the current view relative to its superview, and the x, Y axis value of the point (Frame.origin) in the upper-left corner determines the position of the rectangular region (frame.origin.x, FRAME.ORIGIN.Y); The width (frame.size.width) and height (frame.size.height) determine the area of the rectangle.

2.2 Bounds

Bounds, like frame, is also a rectangular area with a frame-like property, but unlike a frame with its parent view as a reference, the bounds is referenced by the current view, reflecting the position relationship of the current view. Both frame and bound can make the same view (control) in the same position. However, flexible use of frame and bounds according to the actual situation can simplify the code logic and reduce the interdependence of the layout.

2.3 contentsize

Contentsize is a property of Uiscrollview and child controls that inherit from Uiscrollview. Contentsize is a property that determines the Contentview width (contentsize.width) and High (contesize.height) on Uiscrollview.
Uiscrollview can be seen as a two-layer composite view, 1 shows that the upper layer is fixed uiscrollview, the lower layer can be sliding contenview,contenview size can be greater than the upper Uiscrollview.


Figure 1 Uiscrollview hierarchical relationship 2.4 Contentoffset

Contentoffset is a property of Uiscrollview and child controls that inherit from Uiscrollview. Contentoffset determines the distance of the Uiscrollview vertex (the upper-left corner) value relative to the vertex value (that is, frame.origin) of its parent Class View.

2.5 Contentinset

The Contentinset is a property of Uiscrollview and child controls that inherit from Uiscrollview, and Contentinset determines the size of the area that the Contenview expands from the top to the bottom relative to the Uiscrollview. The contentinset is of type uiedgeinsets and the default value is Uiedgeinsetszero.

3. Summary

Frame,bounds,contensize,contentoffset,contentinset is a commonly used property in layouts, and flexible use greatly increases development efficiency, layout flexibility, and the logic of the Code, as described in summary 2 of attributes.


Figure 2 Relationship between layout-related properties

Note: The value of Contentinset in the figure is negative

Reprinted from: http://www.jianshu.com/p/c36d3fb3c833

iOS development frame, contentsize, Contentoffset, contentinset the difference between the analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.