OC 常用结构体
来源:互联网 发布:看漫画学日语知乎 编辑:程序博客网 时间:2024/04/20 06:23
NSRange\\CGRange
A structure used to describe a portion of a series—such as characters in a string or objects in an NSArray object.Declaration
SWIFT
typealias NSRange = _NSRange
typedef struct _NSRange {
NSUInteger location;
NSUInteger length;
} NSRange;
Discussion
Foundation functions that operate on ranges include the following:
NSEqualRanges
NSIntersectionRange
NSLocationInRange
NSMakeRange
NSMaxRange
NSRangeFromString
NSStringFromRange
NSUnionRange
eg:
NSRange range0 = NSMakeRange(2,4);
NSString *str = @"i love oc";
NSRange range = [str rangeOfString:@"java"];
NSLog(@"loc = %ld, length = %ld",range.location,range.length);
NSRange range2 = [str rangeOfString:@"oc"];
NSLog(@"loc = %ld,length = %ld",range2.location,range2.length);
NSPoint\CGPoint
Represents a point in a Cartesian coordinate system.Declaration
SWIFT
typealias NSPoint = CGPoint
typedef struct _NSPoint {
CGFloat x;
CGFloat y;
} NSPoint;
Import Statement
OBJECTIVE-C
@import Foundation;
import Foundation
eg1:
CGPoint p1 = NSMakePoint(10,10);
NSPoint p2 = CGPointMake(20,20);//usual
CGPointZero == CGPointMake(0,0);//It represents the origin
eg2:
//使用这些CGPointEqualToPoint、CGRectContainsPoint等函数的前提是添加CoreGraphics框架
BOOL b = CGPointEqualToPoint(CGPointMake(10,10),CGPointMake(10,10));
NSSize\CGSize
Represents a two-dimensional size.Declaration
SWIFT
typealias NSSize = CGSize
typedef struct _NSSize {
CGFloat width;
CGFloat height;
} NSSize;
Discussion
Normally, the values of width and height are non-negative(非负). The functions that create an NSSize structure do not prevent you from setting a negative value for these attributes. If the value of width or height is negative, however, the behavior of some methods may be undefined.
Import Statement
OBJECTIVE-C
@import Foundation;
SWIFT
import Foundation
eg1:
NSSize s1 = CGSizeMake(100, 50);
NSSize s2 = NSMakeSize(100, 50);
CGSize s3 = NSMakeSize(200, 60);
NSRect\CGRect
Represents a rectangle.Declaration
SWIFT
typealias NSRect = CGRect
typedef struct _NSRect {
NSPoint origin;
NSSize size;
} NSRect;
Import Statement
OBJECTIVE-C
@import Foundation;
import Foundation
eg1:
CGPoint p1 = NSMakePoint(10, 10);
NSPoint p2 = CGPointMake(20, 20);
CGRect r1 = CGRectMake(0, 0, 100, 50);
CGRect r2 = { {0, 0}, {100, 90}};
CGRect r3 = {p1, s2};
eg2:
// 使用CGPointZero等的前提是添加CoreGraphics框架
CGRect r4 = {CGPointZero, CGSizeMake(100, 90)};
// 将结构体转为字符串
//NSString *str = NSStringFromPoint(p1);
//NSString *str = NSStringFromSize(s3);
NSString *str = NSStringFromRect(r1);
NSLog(@"%@", str)
附带代码:http://download.csdn.net/detail/goodboy_wkx/8685319
0 0
- OC 常用结构体
- oc中的常用结构体
- OC之常用结构体
- oc中常用结构体
- OC学习笔记:常用的结构体
- iOS--Foundation框架-OC常用结构体
- 黑马-OC语法-Foundation-常用结构体
- OC特有语法—常用结构体
- OC-050.常用的结构体
- OC中常用的结构体
- OC学习:Foundation框架之常用结构体
- 黑马程序员-OC语言-Foundation框架中的常用结构体
- Foundation -- OC结构体
- OC结构体
- OC结构体
- OC结构体
- 黑马程序员--oc结构体
- OC之Foundation结构体
- DDR3各个频率详解
- 【数据库复习_索引】
- 将英文句子 按单词拆分 并获取range、index
- sqlserver 行转列
- Java根据数据库表格自动生成java实体类
- OC 常用结构体
- 关于LCS的一个证明
- pmap命令
- Scala学习笔记(四) - 变量,常量,函数及类的定义
- 人生小精彩
- mysql学习小结
- 已将该虚拟机配置为64位客户机操作系统,但是无法执行64位操作。此主机支持Intel VT-x,但Intel VT-x禁用
- linux 输入中文
- Weka访问数据库