×

iOS CGRectGetMaxX & CGRectGetMaxY


CGRectGetMaxX & CGRectGetMaxY ?

CGRectGetMaxX is used to get the maximum point of a specified view in x-Direction .

CGRectGetMaxY is used to get the maximum point of a specified view in y-Direction .

Example :-

Final Output will be look like this....


//
//  ViewController.m
//  Created by Manish Methani on 31/03/17.
//  Copyright © 2017 Codzify. All rights reserved.
//


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
  UIView *superView = [[UIView alloc]initWithFrame:CGRectMake(10, 280, 200, 120)];
    [self.view addSubview:superView];
    superView.backgroundColor = [UIColor orangeColor];
    
    
    UIView *firstInnerView = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(superView.frame)  , CGRectGetMaxY(superView.frame) + 12 , 200, 120)];
    [self.view addSubview:firstInnerView];
    firstInnerView.backgroundColor = [UIColor yellowColor];
    
}

In this example, we created a superView .

Frame of SuperView (Orange Color View) :-

CGRectMake(10, 280, 200, 120)

1) x-Coordinate = 10

2) y-Coordinate = 280

3) width = 200

4) height = 120

Then we created a First Inner View . (Yellow Color View)

Frame of firstInnerView :-

CGRectMake(CGRectGetMaxX(superView.frame)  , CGRectGetMaxY(superView.frame) + 12 , 200, 120)
1) x-Coordinate = CGRectGetMaxX(superView.frame)

CGRectGetMaxX is used to get maximum x-Coordinate of specified view inside paranthesis. Here superView's (orangeColor View's) minimum x-coordinate is 10 and maximum x-coordinate will be when orange color view ends . right ? see above. So firstInnerView's (yellow Color View) minimum x-coordinate will be at the end of orangeColor View from top (X-coordinate). That's why , CGRectGetMaxX(superView.frame)

In simple words , End of orangeColor will be min of yellow Color from X-Axis by writing this CGRectGetMaxX(superView.frame) in yellow color frame's x-coordinate.


2) y-Coordinate = CGRectGetMaxY(superView.frame)

CGRectGetMaxY is used to get maximum y-Coordinate of specified view inside paranthesis. Here superView's (orangeColor View's) minimum y-coordinate is 280 and maximum y-coordinate will be when orange color view ends . right ? . So firstInnerView's (yellow Color View) minimum y-coordinate will be at the end of orangeColor View from bottom (Y-coordinate). That's why , CGRectGetMaxY(superView.frame)

In simple words , End of orangeColor will be min of yellow Color from Y-Axis by writing this CGRectGetMaxY(superView.frame) + 12px padding in yellow color frame's y-coordinate.