Usage of CGRectMake in Cocoa in iPhone Development

Source: Internet
Author: User

1. CGRectMake (origin. x, origin. y, size. width. Size. height) defines the rectangle in the code.
For example, [imageView setFrame: CGRectMake (,)];
If you get its own framework, CGFloat x (y) = imageView. frame. origin. x (imageView. frame. origin. y)


Get size: imageView. frame. size. width (imageView. frame. size. height)
Eg:
UILabel * label = [[UILabel alloc] initWithFrame: CGRectZero];
Label. frame = CGRectMake (0, 0,200, 50 );
Label. center = CGPointMake (160,240 );
Label. text = @ "hello everyone ";
Label. textColor = [UIColor redColor];
Label. font = [UIFont fontWithName: @ "Arial" size: 37];
NSLog (@ "% f", label. frame. origin. x );
NSLog (@ "% f", label. frame. origin. y );
NSLog (@ "% f", label. frame. size. height );
NSLog (@ "% f", label. frame. size. width );
NSLog (@ "% f", label. center. x );
NSLog (@ "% f", label. center. y );


2. NSStringFromCGReot (someCGRect) converts the CGRect structure into a formatted string.


3. CGRectFromString (aString) is represented by a string to restore the rectangle.


4. CGRectlnset (aRect) is used to create a smaller or larger rectangle (with the same center point ). Use positive embedded values to represent smaller rectangles, and use negative embedded values to represent larger rectangles.


5. CGRectIntersectsRect (rect 1. feet 2) can determine whether the rectangular structure is cross and whether the two rectangular objects overlap.
Check whether two icons are in conflict.


6. CGRectZero is a rectangle constant with a height and a width of 0 and a position of (0, 0. You can use this constant to create a border but you are not sure about the border size or position.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.