Parent Justification

Center Justification

Using center justification, you can center a view within another view. Once again, this type of justification alters the meaning of viewBounds. We will only look at horizontal center justification, since vertical center justification works the same way, except that it uses the top and bottom coordinates instead of the left and right ones. The view system handles center justification as if the following two-step process were used:

1. First, it centers the view within its parent (see FIGURE 5.18).

2. Then, it adds any horizontal offset specified by the left viewBounds value. If the left viewBounds is positive, the child is offset to the right. If the left viewBounds is negative, the child is offset to the left. For example, if you have a child that is 20 pixels wide and you want to offset it from the center of the parent by 5 pixels to the right, you would give it these viewBounds: left: 5, right: 25 (see FIGURE 5.19).

FIGURE 5.18 : Exact centering of a view within its parent.


FIGURE 5.19 : Setting views off-center by five pixels within their parents.


An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.

Last modified: 1 DEC 1996