---
title: "Fundamentals of CGGeometry in iOS"  
description: "iOS provides a CoreGraphics framework that came from iOS version 2.0. CoreGraphics provides CGGeometry for our iOS application developers that helps i"  
author: "Tarun Kumar"  
published: 2016-02-01  
updated: 2018-03-14  
canonical: https://www.mindstick.com/blog/11013/fundamentals-of-cggeometry-in-ios  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 3 minutes  

---

# Fundamentals of CGGeometry in iOS

iOS provides a CoreGraphics [framework](https://www.mindstick.com/forum/34615/software-framework-vs-library) that came from iOS version 2.0. CoreGraphics provides CGGeometry for our iOS [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) [development](https://www.mindstick.com/articles/65309/importance-of-ux-design-in-the-development-of-mobile-apps) that helps in positioning views or creating drawing by programmatically. CGGeometry is a [collection](https://www.mindstick.com/articles/1718/collections-in-java) of structures, [constants](https://www.mindstick.com/articles/1813/objective-c-constants) and functions. CGGeometry provides many more methods like comparing values, checking memberships, and so on. Some of the methods and data types are described below.

##### CGGeometry have some data types that help to create shapes or designs, these are as follows:

##### CGPoint: it is a basic type for all floating-point values. It takes two

##### CGFloat (float) values for width and height.

##### \
Syntax: struct CGPoint {CGFloat x, CGFloat y};

##### Field x is the x-coordinate of the point and field y is the y-coordinate of the

##### point.

##### CGSize: it is a structure that contains the width and height values. \

##### Syntax: struct CGSize {CGFloat width, CGFloat height};

\

**CGRect:** it is a [structure](https://www.mindstick.com/articles/23258/choose-your-business-structure-wisely) that contains the location and [dimensions](https://www.mindstick.com/forum/1834/c-sharp-xaml-how-to-modify-the-dimensions-of-the-rows-and-the-columns-of-a-grid) of a rectangle. It takes both CGPoint (origin) and CGSize (size) in its parameter. When we use origin and size fields it defines the position and the size of a rectangle.

**Syntax:** struct CGRect {CGPoint origin, CGSize size};

CGVector: it is a structure that contains the two dimensional vector.

Syntax: struct CGVector {CGFloat x, CGFloat y };

**CGGeometry** provides two methods to get [height and width](https://www.mindstick.com/forum/158660/what-is-the-css-property-used-to-specify-the-height-and-width-of-an-element) according to the specified rectangle, these are:

**CGRectGetHeight:** it takes CGRect [reference](https://www.mindstick.com/forum/774/reference-what-does-this-error-mean-in-php) and returns the height of the rectangle.

**Syntax:** CGFloat CGRectGetHeight (CGRect rect);

**CGRectGetWidth:** it also takes CGRect reference and returns the width of the rectangle.

**Syntax:** CGFloat CGRectGetWidth (CGRect rect);

**CGGeometry** provides some methods to get minimum, center and largest values according to the specified rectangle, these are:

**CGRectGetMinX:** it takes CGRect reference and returns the minimum (smallest) value of x-coordinate of the specified rectangle.

**Syntax:** CGFloat CGRectGetMinX(CGRect rect);

**CGRectGetMinY:** it takes CGRect reference and returns the minimum (smallest) value of y-coordinate of the specified rectangle.

**Syntax:** CGFloat CGRectGetMinY(CGRect rect);

**CGRectGetMidX:** it takes CGRect reference and returns the center value of the x-coordinate of the specified rectangle.

**Syntax:** CGFloat CGRectGetMidX(CGRect rect);

**CGRectGetMidY:** it takes CGRect reference and returns the center value of the y-coordinate of the specified rectangle.

**Syntax:** CGFloat CGRectGetMidY(CGRect rect);

CGRectGetMaxX: it takes CGRect reference and returns the height of x-coordinate of the specified rectangle.

Syntax: CGFloat CGRectGetMaxX(CGRect rect);

CGRectGetMaxY: it takes CGRect reference and returns the height of y-coordinate of the specified rectangle.

**Syntax:** CGFloat CGRectGetMaxY(CGRect rect);

**CGGeometry** provides many methods to get the point, according to the specified coordinates, some are:

CGPointMake: it takes two CGFloat reference and returns the point.

**Syntax**: CGPoint CGPointMake (CGFloat x, CGFloat y);

CGRectMake: it takes two coordinates of type CGFloat and size ([width and height](https://www.mindstick.com/forum/158680/what-css-property-is-used-to-set-the-width-and-height-of-an-element)) of type CGFloat, it will return a rectangle using the specified coordinate.

**Syntax**: CGRect CGRectMake (CGFloat x, CGFloat y, CGFloat width, CGFloat height);

---

Original Source: https://www.mindstick.com/blog/11013/fundamentals-of-cggeometry-in-ios

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
