Objective-C中经常使用的结构体NSRange,NSPoint,NSSize(CGSize),NSRect
Objective-C中经常使用的结构体NSRange,NSPoint,NSSize(CGSize),NSRect
1 NSRange
NSRange 的原型为
typedef struct _NSRange {
NSUInteger location;
NSUInteger length;
} NSRange;
NSMakeRange的函数
NS_INLINEz是内联函数
typedef NSRange *NSRangePointer;
NS_INLINE NSRange NSMakeRange(NSUInteger loc, NSUInteger len) {
NSRange r;
r.location = loc;
r.length = len;
return r;
}
用法
//NSRange表示的是范围
NSRange range;
range.location = 18;
range.length = 34; NSLog(@"location is %zi",range.location);
NSLog(@"length is %zi",range.length); //高速创建
range = NSMakeRange(8, 10);
NSLog(@"location is %zi",range.location);
NSLog(@"length is %zi",range.length); //NSStringFromRange将上面的结构体转化成字符串类型,打印出来 NSString* str1 = NSStringFromRange(range); //%@是一个OC对象,range代表的是一个结构体,str是一个OC对象
NSLog(@"rang is %@",str1);
2 NSPoint
NSPoint的原型
struct CGPoint {
CGFloat x;
CGFloat y;
};
NSMakePoint函数
NS_INLINE NSPoint NSMakePoint(CGFloat x, CGFloat y) {
NSPoint p;
p.x = x;
p.y = y;
return p;
}
CGPointMake函数
CGPointMake(CGFloat x, CGFloat y)
{
CGPoint p; p.x = x; p.y = y; return p;
}
用法
//NSPoint指的是位置
NSPoint point; //给结构体里面的点进行赋值
point.x = 10;
point.y = 10; //高速创建点
point = NSMakePoint(10, 18); //常见的是CGPointMake创建点的函数
point = CGPointMake(29, 78);
NSString* str2 = NSStringFromPoint(point);
NSLog(@"point is %@",str2);
3 CGSize
CGSize的原型
struct CGSize {
CGFloat width;
CGFloat height;
};
NSMakeSize函数
NS_INLINE NSSize NSMakeSize(CGFloat w, CGFloat h) {
NSSize s;
s.width = w;
s.height = h;
return s;
}
CGSizeMake函数
CGSizeMake(CGFloat width, CGFloat height)
{
CGSize size; size.width = width; size.height = height; return size;
}
用法
NSSize size;
size.width = 100;
size.height = 12;
size = NSMakeSize(12, 12);
size = CGSizeMake(11, 11);
NSString* str3 = NSStringFromSize(size);
NSLog(@"%@",str3);
4 CGRect
CGRect的原型
struct CGRect {
CGPoint origin;
CGSize size;
};
CGRectMake的函数
CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height)
{
CGRect rect;
rect.origin.x = x; rect.origin.y = y;
rect.size.width = width; rect.size.height = height;
return rect;
}
NSMakeRect函数
NS_INLINE NSRect NSMakeRect(CGFloat x, CGFloat y, CGFloat w, CGFloat h) {
NSRect r;
r.origin.x = x;
r.origin.y = y;
r.size.width = w;
r.size.height = h;
return r;
}
用法
//既包括了尺寸大小和位置
NSRect rect;
rect.origin.x = 12;
rect.origin.y = 14;
rect.size.width = 12;
rect.size.height = 15; //高速创建方法
rect = CGRectMake(12, 12, 12, 12);
rect = NSMakeRect(11, 11, 11, 11); //转化成字符串打印出来
NSString* str5 = NSStringFromRect(rect);
NSLog(@"rect is %@",str5);
Objective-C中经常使用的结构体NSRange,NSPoint,NSSize(CGSize),NSRect的更多相关文章
- Objective-C中常用的结构体NSRange,NSPoint,NSSize(CGSize),NSRect
本节要点:红色标记 需要记下来 1 NSRange typedef struct _NSRange { NSUInteger location; NSUInteger length ...
- Linux中表示“时间”的结构体和相关函数
转载于:http://blog.chinaunix.net/uid-25909722-id-2827364.html Linux中表示“时间”的结构体和相关函数 2011-09-13 17: ...
- FFMPEG中最要害的结构体之间的关系
FFMPEG中最关键的结构体之间的关系 http://www.myexception.cn/program/1404591.html FFMPEG中结构体很多.最关键的结构体可以分成以下几类: a) ...
- Swift面向对象基础(上)——Swift中的类和结构体(下)
学习来自<极客学院> import Foundation class User { var name:String var age:Int init(name:String,age:Int ...
- Swift面向对象基础(上)——Swift中的类和结构体(上)
学习来自<极客学院> import Foundation //1.定义类和结构体 /* [修饰符]calss 类名{ 零到多个构造器 零到多个属性 零到多个方法 零到多个下标 } 修饰符可 ...
- 问题解决——在结构体中使用set保存结构体数据
=====================声明========================== 本文原创,转载请明确的注明出处和作者,并保持文章的完整性(包括本声明部分). 本文链接:http:/ ...
- C语言中的系统时间结构体类型
在C语言涉及中经常需要定时触发事件,涉及到获取系统时间,其结构体类型有多种.Unix/Linux系统下有以下几种时间结构: 1.time_t 类型:长整型,一般用来表示从1970-01-01 00:0 ...
- FFMPEG中最关键的结构体之间的关系
FFMPEG中结构体很多.最关键的结构体可以分成以下几类: a) 解协议(http,rtsp,rtmp,mms) AVIOContext,URLProtocol,URLContext主要 ...
- C语言中内存对齐与结构体
结构体 结构体是一种新的数据类型,对C语言的数据类型进行了极大的扩充. struct STU{ int age; char name[15]; }; struct STU a; //结构体实例 str ...
随机推荐
- Android Mediaplayer 调用release()的时候ANR
先stop,然后再release,最后吧media置为null
- printf格式控制详解
format 参数输出的格式,定义格式为 %[flags][width][.precision][length]specifier specifier在最后面.定义了数据类型. Where the s ...
- Java I/O流-PipedInputStream、PipedOutputStream
一.整体代码图 PipedStreamDemo.java import java.io.*; class PipedStreamDemo { public static void main(Strin ...
- poll系统调用的内核态实现机制分析
版权所有,转载请标明出处 All right reserved,Copyright by 徐行而至 浅唱而归 前面已经比较详尽的分析了系统调用引发的内核执行过程,本文将继续分析一下linux2.6 ...
- Ch02 从零开始实例学习5
演练:添加模型 原文链接:http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-a-model ...
- C#多线程的死锁演示
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- exe4教程
exe4j_windows-x64_5_0_1.exe <?xml version="1.0" encoding="UTF-8"?> <exe ...
- 【linux】 Makefile之make menuconfig /uImage
欢迎转载,转载时请保留作者信息,谢谢. 邮箱:tangzhongp@163.com 博客园地址:http://www.cnblogs.com/embedded-tzp Csdn博客地址:http: ...
- post 请求参数
perl代码: my $login_url='http://192.168.1.1/getpage.gch?pid=1001&logout=1'; my $res = $ua->post ...
- 面试经典-设计包含min函数的栈
问题:设计包含min函数的栈(栈) 定义栈的数据结构,要求添加一个min函数,能够得到栈的最小元素. 要求函数min.push以及pop的时间复杂度都是O(1). 解答:push 和pop的时间复杂度 ...