Zoom
Open masterviewcontroller.xiband view the size of the custome view in the size panel. In this case, it should be the 540x400 size. But the number of readers will be different. No matter how big it is, please write down this number. It's going to be used later.
This will be the minimum size of the app exit. Open mainmenu.xib, select the Window object. In the size panel, tick the minimum size option to the right of constraint, and then modify the width and height to the same value.
Run the program.
Change the size of the exit, this time when the window is reduced to the smallest size, it can no longer be reduced.
Next we need to solve the problem of adaptive size of the control, including the controls in the TableView and detail pages.
The first is the Masterviewcontroller view.
Open Appdelegate.swift, and at the end of the Applicationdidfinishlaunching () method, add:
Set Masterviewcontroller.view the layout constraints = false
Let = Nslayoutconstraint.constraintswithvisualformat("v:|[subview]|",
Options: nslayoutformatoptions(0),
Metrics:Nil,
Views:["SubView": masterviewcontroller.view])
Let = Nslayoutconstraint.constraintswithvisualformat("h:|[subview]|",
Options: nslayoutformatoptions(0),
Metrics:Nil,
Views:["SubView": masterviewcontroller.view])
Nslayoutconstraint.activateconstraints(+ horizontalconstraints)
|
Here, we allow Masterviewcontroller to use automatic layout on two dimensions of width and height.
Next, we use IB's automatic layout to constrain the table view layout so that its height automatically grows when the window size changes, but the width remains constant.
Open masterviewcontroller.xib , select Table View, click the Pin button in the lower right corner, tick the top, left, and bottom 3 constraints, and a width constraint, then click "Add 4 Constraints":
Note that the constraint values in the picture may differ from the reader's actual values.
Then select the Reset button to set its top margin constraint with the table view and a left margin constraint relative to the main view:
Then select the divider line, set its upper and lower margin constraints with the main View, and the left margin constraint with TableView, confirming that bordered Scrollview–table View is selected in the drop-down list for the left margin constraint:
Next, set the "Add" and "Delete" buttons. We don't need to change their size, the only thing that needs to change is the distance between them and the table view. For the two buttons, we need to set their left, top, width, and height constraints. An Add button, for example, appears as follows:
The Delete button is similar.
Run the program, change the window size, and see the effect.
Then the details page on the right. On this page, the width of all controls becomes larger when the window width is larger. In the same way as TableView, set their automatic layout as follows:
· Sets the left and upper constraints on the name label.
· Sets bugTitleView the left and upper constraints.
· Sets the left and upper constraints on the rating label.
· Sets bugRating the left, top, right, and high constraints.
· Sets bugImageView the left, top, bottom, and right constraints.
· Move the Change Picture button so that its right edge is exactly the right bugImageView edge, and then set its right and bottom constraints.
bugImageViewThere may be several warnings when the button is set, but these warnings will be eliminated after the Changepicture button.
When the above steps are done, the storyboard will look like this:
Compile the Run and zoom the window again.
bugImageViewThe scale setting will have a different display effect on the picture. Select the image well control in IB, modify its scaling property to "proportionally up or down" or "Axes independently", and then run the app to see what's different.
Note: If you want to limit the maximum zoom size of a window, you can also limit the size of the window by setting the minimum scale.
Developing Mac Apps with Swift (7)