NSRange,NSPoint,NSSize,NSRect(基础)
来源:互联网 发布:订单系统代码java 编辑:程序博客网 时间:2024/05/22 15:21
//// main.m// test1//// Created by mac on 15/4/24.// Copyright (c) 2015年 mac. All rights reserved.//#import <Foundation/Foundation.h>int main(int argc, const char * argv[]) { @autoreleasepool { /* 常用结构体: NSRange(location,length) NSPoint/CGPoint NSSize/CGSize NSRect/CGRect */ //---------------------------------struct typedef struct date{ int year; int month; int day; } Date; Date d = {2011,4,5}; //赋值顺序可以改变,一目了然 Date d2 ={.year = 234,.day = 243,.month = 34}; /* Declaration: typedef struct _NSRange { NSUInteger location; NSUInteger length; } NSRange; */ //---------------------------------Range NSRange r1 = {2,5};//不用 NSRange r2 = {.location = 234,.length = 34};//不用 NSRange r3 = NSMakeRange(34, 34);//最常用 //查找木个字符窜在str中的范围 //location下标从0开始 NSString *str4 = @"i love you"; NSRange range = [str4 rangeOfString:@"ve 0"]; NSLog(@"loc = %ld, length = %ld",range.location,range.length); //如果找不到,length= 0,location = NSNotFound = -1 NSRange range2 = [str4 rangeOfString:@"gg"]; //range2.location的类型为NSInteger == unsigned long //location使用ld输出为9223372036854775807 NSLog(@"length = %ld,location = %ld\n", range2.location,range2.length); //location使用%d输出为-1 NSLog(@"length = %d,location = %d", range2.location,range2.length); //-1 NSLog(@"%d",NSNotFound); //------------------------------------Point /* Declaration: struct CGPoint { CGFloat x; CGFloat y; }; typedef struct CGPoint CGPoint; */ CGPoint p1 = NSMakePoint(23, 43); CGPoint p2 = CGPointMake(3, 34); //------------------------------------Size /* Declaration: struct CGSize { CGFloat width; CGFloat height; }; typedef struct CGSize CGSize; */ CGSize s1 = CGSizeMake(43, 4); CGSize s2 = NSMakeSize(34, 34); //-------------------------------------Rect /* Declaration: struct CGRect { CGPoint origin; CGSize size; }; typedef struct CGRect CGRect; */ CGRect re1 = CGRectMake(34, 34, 43, 5); CGRect re2 = NSMakeRect(34, 24, 34, 53); //第一个参数是一个点,第二个是宽高范围 CGRect re3 = {p1,s1}; CGRect re4 = {{0,0},{24,65}}; //-------------------------------------- //NextStep公司推出的Foundation框架,函数以NS开头 //使用前提添加CoreGraphics框架 //一些CG方法依赖另一个框架:选中工程项目--TARGETS--Build Phases--Link Binary Libraries--添加CoreGraphics frameWor //比较点是否相等 BOOL isEaual = CGPointEqualToPoint(p1, p2); //CGSizeEqualToSize(<#CGSize size1#>, <#CGSize size2#>) //CGRectEqualToRect(<#CGRect rect1#>, <#CGRect rect2#>) NSLog(@"%d",isEaual); //CGPointZero == CGPointMake(0, 0); //CGSizeZero ==CGSizeMake(0, 0); //CGRectZero == CGRectMake(0, 0, 0, 0); //判断一个点是否在一个矩形框里面 //CGRectContainsPoint(<#CGRect rect#>, <#CGPoint point#>) //打印结构体 NSLog(@"x = %f, y = %f , width = %f, heigt = %f" ,re1.origin.x, re1.origin.y,re1.size.width,re1.size.height ); //调用库方法,先转为字符串对象,再打印 NSString *str = NSStringFromPoint(p1); NSString *str1 = NSStringFromSize(s1); NSString *str2 = NSStringFromRect(re1); NSString *str3 = NSStringFromRange(r1); NSLog(@"%@ \n%@\n%@\n%@\n",str,str1,str2,str3); //自定义命名函数 //-(CGRect) myRect(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; //} } return 0;}
0 0
- NSRange,NSPoint,NSSize,NSRect(基础)
- NSRange、NSSize、NSPoint、NSRect
- 【Foundation】16-NSRange、NSPoint、NSSize、NSRect知识点
- OC基础-Foundation——常用结构体 (NSRange 、NSPoint、NSsize、NSRect)
- 黑马程序员08--Foundation--01--NSString、NSRange、NSPoint、NSSize、NSRect
- Foundation框架中的结构体(NSRange/NSPoint/NSSize/NSRect)
- 【Foundation学习笔记】常用结构体--NSRange、NSPoint、NSSize、NSRect
- NSPoint、NSSize、NSRect、NSRange使用与Bool细节
- foundation的使用——NSRange NSPoint NSSize NSRect
- NSPoint,NSSize,NSRect
- OC--Foundation-NSPoint,NSSize,NSRect
- Foundation中的NSPoint/NSSize/NSRect
- 20120810-课堂笔记--FoundationKit,NSRange,NSPoint,NSSize,NSRect,可变对象
- Foundation——常用结构体 (NSRange 、NSPoint、NSsize、NSRect)
- Objective-C中常用的结构体NSRange,NSPoint,NSSize(CGSize),NSRect
- 黑马程序员-----Foundation常用的结构体(NSRange,NSPoint,NSSize,NSRect)
- Objective-C 【NSPoint&CGPoint-NSSize&CGSize-NSRect&NSRect】
- 黑马程序员——iOS开发——oc——founctation中常用结构体(NSRange、NSPoint\CGPoint、NSSize\CGSize、NSRect\CGRect)
- Swift下xcode6实现加载外部或者框架的方法
- ButterKnife--View注入框架
- JAVA Debug调试技术
- 思科CCNA第四学期第五章答案
- 系统软件
- NSRange,NSPoint,NSSize,NSRect(基础)
- 对称加密之DES
- Eclipse插件8
- Android开发之getResponseCode抛出异常
- Linux下之使用简单3种创建文件的命令,并实现一个Html和JavaScript小程序
- 移植较新(Linux3.19)内核至mini2440开发板(一)
- HDU1232 畅通工程
- Java基础第八讲
- 字符编码