下面是使用“myView”的“frame”属性更详细的解释:
[self.myView.frame = CGRectMake(x, y, width, height)];
Where:
- x, coordinate FOR the top left corner of your view having as
reference the top left corner of its parents "x" coordinate.
- y, same
as x but y axis
- width, horizontal size of the frame
- height, vertical size of the frame
i.E. You have a view which fits to the screen bounds, so its coordinate (0,0) will be the same as your device screen top left corner.
if you want to add a subview barely smaller that the screen size and center it horizontally and vertically, here is the set up:
[self.myView.frame = CGRMake ( 20 , 20 , self.view.frame.size.width-40, self.view.frame.size.height-40);
This example sets the frame inside the view and centered. Note that we subtract 40 to the width corresponding to: 20 left side, 20 right side, and so the same for vertical adjustments.
This code will also work in portrait and landscape mode.