您的位置:首页 > 其它

os开发之封装自定义的结构体对象,CGRect,CGSize常用结构体基本使用

2015-09-15 11:51 399 查看
方法如下:

typedef  struct{  //自定义一个结构体
    int age;
    int number;
}Student;

NSValue *stu=[NSValue valueWithBytes:&stu objCtype :@encode(Student)];//把结构体封装成一个对象

Student  value2;//定义一个结构体变量来接受从NSValue得到的结构体

[stu getValue:&value2];//把 stu对象中的结构体取出来

int a=value2.age;  //取得结构体中的字段

其他,系统自带的

CGPoint p=[value  CGPointValue];

系统自带的创建 NSValue 和  获取 CG结构体值的方法

    NSValue *v=[NSValue valueWithCGRect:CGRectMake(0, 0, 0, 0)];
    CGRect rect=[v CGRectValue];
    NSValue *v2=[NSValue valueWithCGSize:CGSizeZero];
    CGSize size=[v2 CGSizeValue];
    NSValue *v3=[NSValue valueWithCGPoint:CGPointMake(0, 0)];
    CGPoint p=[v3 CGPointValue];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: