Introduction to the iOS Foundation framework

Source: Internet
Author: User

1. After the Xcode tool is installed, it will bring with it the frameworks that are commonly used in development. The storage address path is:

/Applications/Xcode. app/Contents/Developer/Platforms/iPhoneOS. platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/Frameworks/

2. In iOS development, the Foundation framework is the most basic framework. The Foundation framework contains common classes and data types, such as struct and enumeration.

3. To use the Foundation framework, you only need to include its primary header file <Foundation/Foundation. h>. The header file contains all header files in the framework.

4. Structures commonly used in the Foundation framework:

Nsange, NSPoint \ CGPoint, NSSize \ CGSize, NSRect \ CGRect

(1) The general usage of struct is as follows:

             Date date = {,,     Date date2 = {.year=, .day=, .month=};

 

(2) nsange struct: used to describe the range

  • View the officially defined nsange
typedef     NSUInteger length;      } NSRange;

  • Brief description and usage of nsange
        NSRange r1 = {,    NSRange r2 = {.location = , .length =          NSRange r3 = NSMakeRange(, ); 
  • Find the nsange of certain characters in the NSString class object in the entire class Object
*str = 
NSRange range = [str rangeOfString:
NSLog(,range.location,rang.length);

 

        # define CGFLOAT_TYPE                 typedef     typedef CGPoint NSPoint;

 

        CGPoint point = NSMakePoint(, );      NSPoint point2 = CGPointMake(, ); 

 

(3) NSSize struct: Describes the size (width and height) of the element, and definesSimilar to NSPoint, we will not repeat it again. The general usage is as follows:

 

    CGSize size = NSMakeSize(, = CGSizeMake(, ); 

 

(4) CGRect struct: used to describe the position (CGPoint) and size (CGSize) of an element.

  • Officially defined CGRect
  CGSize size;    };
typedef CGRect CGRect;
  • General Usage
        CGRect rect = CGRectMake(, , ,     NSRect rect2 = NSMakeRect(, , , );
  • Other usage




CGRect rect = {{,},{, NSPoint point = CGPointMake(, = CGSizeMake(, = CGRect rect3 = {CGPointZero,CGSizeMake(, )};

 

(5) simulate the implementation process of the CGRectMake Function

    rect.origin.x ==    rect.size.width ==

 

5. How to quickly view values in struct

  • Method 1: extract values from struct in sequence
    NSRect rect = CGRectMake(, , ,       NSLog(
    NSRect rect = CGRectMake(, , ,     NSString *strRect =    NSLog(,strRect);

 

6. Common struct Functions

  • Common struct functions are under the CoreGraphics. framework.

 

  • Common Methods
        BOOL pointIsEqual = CGPointEqualToPoint(CGPointMake(, ), CGPointMake(,     BOOL sizeIsEqual = CGSizeEqualToSize(CGSizeMake(, ), CGSizeMake(,     CGRect rect1 = {{,},{,    NSPoint point = CGPointMake(, = CGSizeMake(, =    BOOL rectIsEqual =    BOOL isContent = CGRectContainsPoint(rect1, CGPointMake(, ,isContent);

Related Article

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.