×

iOS CGRectGetMinX & CGRectGetMinY


CGRectGetMinX & CGRectGetMinY ?

CGRectGetMinX is used to get the minimum point of a specified view in x-Direction .

CGRectGetMinY is used to get the minimum 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(120, 280, 200, 120)];
    [self.view addSubview:superView];
    superView.backgroundColor = [UIColor orangeColor];
    
    
    UIView *firstInnerView = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMinX(superView.frame)  , CGRectGetMinY(superView.frame) - 12 - 120, 200, 120)];
    [self.view addSubview:firstInnerView];
    firstInnerView.backgroundColor = [UIColor yellowColor];
    
}

In this example, we created a superView .

Frame of SuperView (Orange Color View) :-

CGRectMake(120, 280, 200, 120)

1) x-Coordinate = 120

2) y-Coordinate = 280

3) width = 200

4) height = 120

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

Frame of firstInnerView :-

CGRectMake(CGRectGetMinX(superView.frame)  , CGRectGetMinY(superView.frame) - 12 - 120, 200, 120)
1) x-Coordinate = CGRectGetMinX(superView.frame)

CGRectGetMinX is used to get minimum x-Coordinate of specified view inside paranthesis. Here superView's (orangeColor View's) minimum x-coordinate is 120 right ? see above. So firstInnerView's (yellow Color View) minimum x-ccordinate will be 120 by writing this , CGRectGetMinX(superView.frame)

2) y-Coordinate = CGRectGetMinY(superView.frame) - 12 - 120

CGRectGetMinY is used to get minimum y-Coordinate of specified view inside paranthesis. Here superView's (orangeColor View's) minimum y-coordinate is 280 right ? see above. So firstInnerView's (yellow View's) minimum y-ccordinate will be 280 by writing this , CGRectGetMinY(superView.frame)

Now what we want is, we will get minimum y-Coordinate of orangeColor view , leave 12 px from upper side , and give it height of 120. That's why ,

CGRectGetMinY(superView.frame) - 12 - 120

Try removing -120 from above line you will see the effect. This 120 is the height of yellowCOlor view. It will look like this. Because yellow color view starts at 280 - 12 y-coordinate and from that point it's height will be considered which is 120 so it look like this. If you want the final output image , frame for y-coordinate will be 280 - 12 - 120.


3) width = 200 4) height = 120