Obeject-C 结构体 NSRange NSPoint NSSize NSMakeRect
来源:互联网 发布:抢购软件哪个好 编辑:程序博客网 时间:2024/06/05 08:48
NSRange的定义
typedef struct _NSRange
{
NSUInteger location;
NSUInteger length;
} NSRange;
NSRange是一个结构体,其中location是一个以0为开始的index,length是表示对象的长度。他们都是NSUInteger类型。NSRange的方法:NSEqualRanges()NSIntersectionRange()
NSLocationInRange()
NSMakeRange()
NSMaxRange()
NSRangeFromString()
NSStringFromRange()
NSUnionRange()
#import <Foundation/Foundation.h>int main(int argc, const char * argv[]){ @autoreleasepool { //创建 NSRange NSRange range=NSMakeRange(0, 2);//0表示位置 2表示长度 NSLog(@"(%li,%li)",range.location,range.length);//输出 (0,2) //也可如下输出,输出的是 NSString NSLog(@"%@",NSStringFromRange(range));//输出 {0, 2} //用 NSRange 截取 NSString NSString *pStr=@"string"; NSString *pStr2=[pStr substringWithRange:range]; NSLog(@"%@",pStr2);//输出 st //在 NSString 中查找 另一个 字符串(NSString)返回NSRange类型 NSRange range2=[pStr rangeOfString:@"st"]; NSLog(@"(%li,%li)",range2.location,range2.length);//输出 (0,2) //如果没有该字符串则 range3.length=0 //示例 NSRange range3=[pStr rangeOfString:@"stt"]; if (range3.length==0) { NSLog(@"%@",NSStringFromRange(range3)); NSLog(@"没有找到"); } else { NSLog(@"%li,%li",range3.location,range3.length); } //输出结果:{9223372036854775807, 0} 没有找到 //NSEqualRanges()判断两个范围是否相等 返回BOOL类型 //相等返回YES BOOL Bool= NSEqualRanges(range,range2); NSLog(@"%i",Bool); //NSIntersectionRange()方法不常用 不知道什么意思 好像是交叉什么的 //有知道的说以一下 NSRange range4= NSIntersectionRange(range, NSMakeRange(1,2)); NSLog(@"%@",NSStringFromRange(range4));//{1, 1} return 0;}}
另外结构体:NSPoint NSSize NSMakeRect 如下:
#import <Foundation/Foundation.h>int main(int argc, const char * argv[]){ @autoreleasepool { // NSPoint的定义 /* typedef struct _NSPoint { CGFloat x; CGFloat y; } NSPoint; */ //初始化 NSPoint 结构体 NSPoint point=NSMakePoint(3, 4); //输出 NSLog(@"%@",NSStringFromPoint(point));//以 NSString 格式输出 {3, 4} //从NSPoint获取x,y坐标 int xCoord=point.x; int yCoord=point.y; NSLog(@"x=%i,y=%i",xCoord,yCoord);//输出 x=3,y=4 //NSSize的定义 /* typedef struct _NSSize { CGFloat width;//should never be negative CGFloat height;// should never be negative } NSSize; */ //初始化 NSSize (表尺寸) NSSize size=NSMakeSize(3.5, 4.5); // 说明:3.5是width,4.5是height NSLog(@"%@",NSStringFromSize(size)); //输出 {3.5, 4.5} float width=size.width; float height=size.height; NSLog(@"width=%f,height=%f",width,height); //输出 width=3.500000,height=4.500000 //NSMakeRect 初始化 NSRect rect=NSMakeRect(0, 0, 20, 10); NSLog(@"%@",NSStringFromRect(rect)); //输出 {{0, 0}, {20, 10}} //说明{0,0}确定位置,{20,10} 确定尺寸大小 } return 0;}
- Obeject-C 结构体 NSRange NSPoint NSSize NSMakeRect
- Foundation框架中的结构体(NSRange/NSPoint/NSSize/NSRect)
- 【Foundation学习笔记】常用结构体--NSRange、NSPoint、NSSize、NSRect
- Objective-C中常用的结构体NSRange,NSPoint,NSSize(CGSize),NSRect
- NSRange、NSSize、NSPoint、NSRect
- Foundation——常用结构体 (NSRange 、NSPoint、NSsize、NSRect)
- OC基础-Foundation——常用结构体 (NSRange 、NSPoint、NSsize、NSRect)
- 黑马程序员-----Foundation常用的结构体(NSRange,NSPoint,NSSize,NSRect)
- NSRange,NSPoint,NSSize,NSRect(基础)
- 【Foundation】16-NSRange、NSPoint、NSSize、NSRect知识点
- Objective——C Foundation——常用结构体 (NSSRange 、NSPoint、NSsize、NSRect)
- 黑马程序员——iOS开发——oc——founctation中常用结构体(NSRange、NSPoint\CGPoint、NSSize\CGSize、NSRect\CGRect)
- 黑马程序员08--Foundation--01--NSString、NSRange、NSPoint、NSSize、NSRect
- NSPoint、NSSize、NSRect、NSRange使用与Bool细节
- foundation的使用——NSRange NSPoint NSSize NSRect
- 学习笔记:Foundation(1)---NSRange结构体、NSPoint结构体
- 结构体NSPoint、NSRect、与NSSize或CG开头的详解
- 20120810-课堂笔记--FoundationKit,NSRange,NSPoint,NSSize,NSRect,可变对象
- hdu-1256-画8
- 关键字final的用法!!
- OpenCORE_OverView
- hdu-2134-Cuts the cake
- Android中OnScrollListener回调具体剖析
- Obeject-C 结构体 NSRange NSPoint NSSize NSMakeRect
- nyoj-312-20岁生日
- java 采集论坛
- 提高编程的10种能力
- Qt之一个鼠标和按键响应事件演示
- CImage从资源中加载图片文件
- Android listview去除边缘阴影色
- uva 10655 Contemplation! Algebra 矩阵快速幂
- LeetCode-Triangle