zoukankan      html  css  js  c++  java
  • NSRect 位置和尺寸

    前言

    • 结构体 这个结构体用来表示事物的坐标点和宽高度。
    typedef CGRect NSRect;
    
    struct CGRect {
    	CGPoint origin;
    	CGSize size;
    };
    
    typedef struct CGRect CGRect;
    

    1、NSRect 结构体变量的创建与调用

    // NSRect 结构体变量的创建与赋值
    
    // 先定义变量,再赋值
    NSRect rect1;
    rect1.origin.x = 6;
    rect1.origin.y = 1;
    rect1.size.width = 1;
    rect1.size.height = 6;
    
    // 定义时直接赋值,或者  NSRect rect2 = {{7, 2}, {2, 7}};
    NSRect rect2 = {7, 2, 2, 7};
    
    // 给指定成员赋值
    NSRect rect3 = {.size.height = 8, .size.width = 3, .origin.y = 3, .origin.x = 8};
    
    // 使用函数赋值
    NSRect rect4 = NSMakeRect(9, 4, 4, 9);
    
    // 使用等价的结构体定义,等价于 CGRect rect5 = CGRectMake(10, 5, 5, 10);
    NSRect rect5 = CGRectMake(10, 5, 5, 10);
    
    // NSRect 结构体变量值的调用
    
    NSLog(@"rect1: %.0f, %.0f, %.0f, %.0f", rect1.origin.x, rect1.origin.y, rect1.size.width, rect1.size.height);
    NSLog(@"rect2: %.0f, %.0f, %.0f, %.0f", rect2.origin.x, rect2.origin.y, rect2.size.width, rect2.size.height);
    NSLog(@"rect3: %.0f, %.0f, %.0f, %.0f", rect3.origin.x, rect3.origin.y, rect3.size.width, rect3.size.height);
    NSLog(@"rect4: %.0f, %.0f, %.0f, %.0f", rect4.origin.x, rect4.origin.y, rect4.size.width, rect4.size.height);
    NSLog(@"rect5: %.0f, %.0f, %.0f, %.0f", rect5.origin.x, rect5.origin.y, rect5.size.width, rect5.size.height);
    

    2、NSRect 与 NSString 的相互转换

    // NSRect 转 NSString
    NSString *stringFronRect = NSStringFromRect(rect5);
    
    // NSString 转 NSRect
    NSRect rect6 = NSRectFromString(stringFronRect);
    
  • 相关阅读:
    在sed中怎么样产生控制字符^M
    递归遍历目录的shell脚本
    递归法遍历目录查找文件
    【30.01%】【hdu 3397】Sequence operation
    【23.68%】【hdu 2871】Memory Control
    【33.18%】【hdu 5877】Weak Pair (3种解法)
    【38.96%】【hdu 1540】Tunnel Warfare
    【26.8%】【CF 46D】Parking Lot
    【35.20%】【CF 706D】Vasiliy's Multiset
    【33.20%】【LA 4320】【Ping pong】
  • 原文地址:https://www.cnblogs.com/CH520/p/9448212.html
Copyright © 2011-2022 走看看