What's the difference between height and maxY, and width and maxW?
Asked Answered
N

1

5

From the Apple Documentation, the maxY of a view is

The largest value for the y-coordinate of the rectangle.

The maxX of a view is

The largest value of the x-coordinate for the rectangle.

Also from the Apple Documentation, the width of a view is

The width of the specified rectangle.

The height of a view is

The height of the specified rectangle.

If the view being specified took up the whole screen, then what would be the difference between these properties, and when should I use each?

Noellanoelle answered 1/7, 2018 at 16:6 Comment(0)
B
19

They are the same when the origin is 0,0 but quite different otherwise.

Imagine the CGRect with x: 10, y: 30, width: 15, height: 40

Obviously width is 15 and height is 40. But maxX is 25 and maxY is 70.

Basically, maxX is origin.x + width and maxY is origin.y + height.

The above assumes a "normal" rectangle with a positive width and height. When you have a negative width or height, the calculation for maxX or maxY are a little different.

Baileybailie answered 1/7, 2018 at 16:7 Comment(2)
rmaddy, I have a question. By the 'origin', you mean the origin of the view controller, or the view itself?Noellanoelle
Only a view has a frame.Baileybailie

© 2022 - 2024 — McMap. All rights reserved.