Objective-C: una alternativa a la utilización de CGRectMake
Lunes, 27 de julio 2009 CGRectMake() es una función (en realidad una línea # define) utiliza mucho, especialmente cuando se crea objetos de código o la interfaz gráfica de usuario. Su uso es por lo tanto a menudo vinculados componentes de inicialización UIKit sino también a UIView simple o UIImageView CGRectMake() devuelve una struct (tipo de estructura) CGRect
- struct (CGRect
- Origen CGPoint;
- Tamaño CGSize;
- );
- typedef struct CGRect CGRect;
Que a su vez se compone de dos diferentes struct CGPoint y CGSize
- struct (CGPoint
- CGFloat x;
- Y CGFloat;
- );
- typedef struct CGPoint CGPoint;
- Tallas * /. * /
- struct (CGSize
- Ancho CGFloat;
- Altura CGFloat;
- );
- typedef struct CGSize CGSize;
Eso, a su vez, aún contienen los tipos CGFloat o float Si analizamos el código de CGRectMake () son:
- CG_INLINE CGRect
- CGRectMake (CGFloat x, y CGFloat, CGFloat anchura, altura CGFloat)
- (
- Rect CGRect;
- y; = x rect.origin.x; rect.origin.y = y;
- height; width = rect.size.width; rect.size.height = altura;
- rect retorno;
- )
De ello se deduce, por tanto, que esta parte de código:
- UIButton buttonWithType : UIButtonTypeRoundedRect ] ; UIButton * gbutton = [buttonWithType UIButton: UIButtonTypeRoundedRect];
- 12,409,100,40 ) ; gbutton.frame = CGRectMake (12,409,100,40);
- @ "Press" forState : UIControlStateNormal ] ; [SetTitle Gbutton: @ "Prensa" Forst: UIControlStateNormal];
- gbutton ] ; [AddSubview MainWindow: gbutton];
Con razón se puede escribir como:
- UIButton buttonWithType : UIButtonTypeRoundedRect ] ; UIButton * gbutton = [buttonWithType UIButton: UIButtonTypeRoundedRect];
- 12,409,100,40 } ; = gbutton.frame (CGRect) (12,409,100,40);
- @ "Press" forState : UIControlStateNormal ] ; [SetTitle Gbutton: @ "Prensa" Forst: UIControlStateNormal];
- gbutton ] ; [AddSubview MainWindow: gbutton];
Sólo para acelerar la ejecución de código un poco '... ![]()














La curiosidad ": si quieres aprender Obj-C, por ejemplo, a partir de cero o casi, en que las publicaciones que no puedes pagar?
@ Cristian: Google Book Search (Google Books), hay muchos recursos (en Inglés) es prácticamente completa.