How to declare my very own CGRectZero like constant?

前端 未结 4 1641
失恋的感觉
失恋的感觉 2021-01-31 18:54

This is a newbie C/Objective-C question :-)

Let say I want a CGRectOne and a CGRectTwo constants.

How can I declare that?

Thanks, Jérémy

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-31 19:48

    There are a couple of options. With C89,

    const CGRect CGRectOne = { { 0.0f, 0.0f }, { 1.0f, 1.0f } };
    

    With C99,

    const CGRect CGRectOne = {
        .origin.x = 0.0f,
        .origin.y = 0.0f,
        .size.width = 1.0f,
        .size.height = 1.0f
    };
    

    or

    const CGRect CGRectOne = {
        .origin = { .x = 0.0f, .y = 0.0f },
        .size   = { .width = 1.0f, .height = 1.0f }
    };
    

提交回复
热议问题