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 ...
随机推荐
- js动态向页面中添加表格
我们在实际开发中经常会想要实现如下情况: 点击某个按钮,然后动态的网页面里面添加一个表格或者一行,这个更加灵活方便.但是实现起来肯定不能像在页面里面直接写标签来的容易,以下是我项目中的代码,拿过来分享 ...
- ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables opt
mysql跳过权限: mysqld -nt --skip-grant-tables opt 登录:mysql -uroot -p 修改root密码 set password for 'root'@'l ...
- oralce 简单错误汇集。。。。。
1.ora-12560 TNS:协议适配器错误 实例名被错误修改或者oracle 服务没有正常启动.
- POJ 2031 prim
Building a Space Station Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4400 Accepted: 2 ...
- c语言,内存字节对齐
引用:内存字节对齐 写出一个struct,然后sizeof,你会不会经常对结果感到奇怪?sizeof的结果往往都比你声明的变量总长度要大,这是怎么回事呢?讲讲字节对齐吧. /************* ...
- [VBS]_[活动分组程序]
场景: 1.每次搞活动都需要分组,比如20个人分3个组,如何才能更公平的分组,想到的只能是随机分组程序. 2.时间关系并没有实现男女平衡的分组,有时间的哥们可以自己实现. 文件1:分组程序.vbs,记 ...
- 基于visual Studio2013解决面试题之1310随机数
题目
- opencv之haar特征+AdaBoos分类器算法流程(二)
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/ ...
- EEPlat PaaS VS Saleforce force.com
综述 EEPlatPaaS和Saleforce的Force.com都是元数据驱动应用的解决方式.整体而言,Force.com提供了更上层的解决方式,屏蔽了SQL语句.数据库:EEPlat更加底层,有更 ...
- Winform - 判断GroupBox控件中的TextBox文本框是不是为空
foreach (Control item in this.groupBox2.Controls) { if (item is TextBox) { if (item.Text.Trim() == & ...