我有一个结构,我在其中定义正方形的大小(宽度,高度),而且我不知道为什么代码不能很好地工作。这是我正在使用的代码:
.h
struct size{
int width;
int height;
};
.m
struct size a;
a.width = 508;
a.height = 686;
// I use it here.
有任何想法吗?
最佳答案
如果要使用Apple提供的类型,您可以:
CGSize
用于大小(带有width
和height
)CGPoint
(带有x
和y
)CGRect
,两者结合在一起。 用法示例:
CGPoint p;
CGSize s;
CGRect r;
p.x = 1;
p.y = 2;
// or:
p = CGPointMake(1, 2);
s.width = 3;
s.height = 4;
// or:
s = CGSizeMake(3, 4);
r.origin.x = 1;
r.origin.y = 2;
r.size.width = 3;
r.size.height = 4;
// or:
r.origin = p;
r.size = s;
// or:
r = CGRectMake(1, 2, 3, 4);
关于iphone - 如何正确定义结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9117536/