Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGSizeMake Doesn't Work for Constant

Tags:

objective-c

Is there a way to do this type of thing?

static const CGSize maxPageSize = CGSizeMake(460, 651);

This is illegal because "Initializer element is not a compile-time constant."

I could use individual floats, of course, but I'm wondering if there's a way to do this.

like image 475
Dan Rosenstark Avatar asked Sep 04 '12 17:09

Dan Rosenstark


2 Answers

Since CGSize is just a simple C-struct:

struct CGSize {
  CGFloat width;
  CGFloat height;
};
typedef struct CGSize CGSize;

You can use an initializer list:

static const CGSize maxPageSize = {460, 651};
like image 129
Matt Wilding Avatar answered Oct 13 '22 17:10

Matt Wilding


CGSize

A structure that contains width and height values.

struct CGSize {
   CGFloat width;
   CGFloat height;
};
typedef struct CGSize CGSize;

Fields width A width value. height A height value.

const CGSize CGSizeZero;

e.g

static const CGSize pageSize = {320, 480};
like image 29
prashant Avatar answered Oct 13 '22 19:10

prashant