Sam
Sam

Reputation: 621

CGRectMake coordinates refers to which coordinates

We use CGRectMake to set the width,height and x and y ordinates but x and y refers to which coordinates is of the root view and if yes then if I create an child view and then add this button to the child view then which coordinates it will refer to which coordinates?

UIButton *roundRectButton = [UIButton buttonWithType:

UIButtonTypeRoundedRect];

[roundRectButton setFrame:CGRectMake(60, 50, 200, 40)];

Upvotes: 0

Views: 174

Answers (2)

Himanshu Joshi
Himanshu Joshi

Reputation: 3399

When you set the frame, it means you are positioning it with respect to its superview and when you use bounds, it means you are positioning it with the real (x,y) coordinates of device.

Here you are setting the frame of the view(i.e. UIButton) so you are positioning it with respect to its parentView.

Upvotes: 1

Jacopo Berta
Jacopo Berta

Reputation: 265

A UIView coordinates system refers to its superview and has its orignin in the top-left corner of its superview. As stated here

The default coordinate system in UIKit has its origin in the top-left corner and has axes that extend down and to the right from the origin point. Coordinate values are represented using floating-point numbers, which allow for precise layout and positioning of content regardless of the underlying screen resolution. Figure 1-4 shows this coordinate system relative to the screen. In addition to the screen coordinate system, windows and views define their own local coordinate systems that allow you to specify coordinates relative to the view or window origin instead of relative to the screen.

So your uibutton coordinate system will refer to its super UIView.

Upvotes: 0

Related Questions