Articles Tagged 'float'

Objective-C: an alternative to using CGRectMake

CGRectMake() is a function (actually an inline # define) used a lot especially when you create graphics objects from code or user interface. o UIImageView . CGRectMake() restituisce una struct (struttura di tipo) CGRect : Its use is therefore often associated initialization components of UIKit , but also to simple UIView or UIImageView . CGRectMake() returns a struct (structure type) CGRect :

1
2
3
4
5
struct {CGRect
CGPoint origin;
CGSize size;
};
typedef struct CGRect CGRect;

: Which in turn is composed of two different struct CGPoint and CGSize :

1
2
3
4
5
6
7
8
9
10
11
12
13
struct {CGPoint
CGFloat x;
CGFloat y;
};
typedef struct CGPoint CGPoint;

/ * Sizes. * /

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

. That, in turn, again, contain types CGFloat or type float . If we analyze the code of CGRectMake () are:

1
2
3
4
5
6
7
8
CG_INLINE CGRect
CGRectMake (CGFloat x, y CGFloat, CGFloat width, height CGFloat)
{
CGRect rect;
y; rect.origin.x = x, y = rect.origin.y;
height; rect.size.width = width, height = rect.size.height;
return rect;
}

It follows, therefore, that this piece of code:

1
2
3
4
[ UIButton buttonWithType : UIButtonTypeRoundedRect ] ; UIButton gbutton * = [UIButton buttonWithType: UIButtonTypeRoundedRect];
12 , 409 , 100 , 40 ) ; gbutton.frame = CGRectMake (12, 409, 100, 40);
@ "Press" forState : UIControlStateNormal ] ; [Gbutton setTitle: @ "Press" Forst: UIControlStateNormal];
gbutton ] ; [MainWindow addSubview: gbutton];

It could rightly be written as:

1
2
3
4
[ UIButton buttonWithType : UIButtonTypeRoundedRect ] ; UIButton gbutton * = [UIButton buttonWithType: UIButtonTypeRoundedRect];
CGRect ) { 12 , 409 , 100 , 40 } ; gbutton.frame = (CGRect) {12, 409, 100, 40};
@ "Press" forState : UIControlStateNormal ] ; [Gbutton setTitle: @ "Press" Forst: UIControlStateNormal];
gbutton ] ; [MainWindow addSubview: gbutton];

Just to speed things up 'the code is running ... :)

Continued ...