iphone - 如何正确定义结构

标签 iphone objective-c ios struct

我有一个结构,我在其中定义正方形的大小(宽度,高度),而且我不知道为什么代码不能很好地工作。这是我正在使用的代码:

.h
  struct size{
        int width;
        int height;
   };

.m

   struct size a;
    a.width = 508;
    a.height = 686;
// I use it here.

有任何想法吗?

最佳答案

如果要使用Apple提供的类型,您可以:

  • CGSize用于大小(带有widthheight)
  • 位置的CGPoint(带有xy)
  • 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/

    相关文章:

    ios - 照片库共享未显示我的应用程序 ios

    objective-c - NSInteger 到 8 位格式的二进制(字符串)值

    ios - 无法从 ios 中的当前 View Controller 调用导航 Controller

    ios - 从 Facebook WebView 中打开 iOS 深层链接停止工作

    ios - 如何从 Objective C 中的文件创建私钥?

    iphone - UITableView子菜单

    php - ajax 不再适用于 iPhone

    iphone - iPhone 的汇编 (.s) 代码中的条件编译 - 如何进行?

    ios - 'NSInvalidArgumentException',原因:'-[NSNull objectAtIndex:]:无法识别的选择器已发送到实例

    ios - 创建私有(private) cocoapod,git 标签问题