Artigos com a tag 'CGFloat'

Objective-C: uma alternativa ao uso CGRectMake

CGRectMake() é uma função (na verdade uma linha # define) muito utilizada, especialmente quando você criar gráficos a partir de objetos de código ou interface do usuário. o UIImageView . CGRectMake() restituisce una struct (struttura di tipo) CGRect : Seu uso é, portanto, muitas vezes associada a inicialização de componentes UIKit , mas também a simples UIView ou UIImageView . CGRectMake() retorna um struct (tipo de estrutura) CGRect :

1
2
3
4
5
struct {CGRect
CGPoint origem;
CGSize tamanho;
};
typedef struct CGRect CGRect;

: Que por sua vez é composta de duas diferentes struct CGPoint e CGSize :

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

Tamanhos / *. * /

struct {CGSize
CGFloat largura;
CGFloat altura;
};
CGSize CGSize typedef struct;

. Que, por sua vez, outra vez, contêm tipos CGFloat ou tipo de float . Se analisarmos o código de CGRectMake () são:

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

Segue-se, portanto, que este pedaço de código:

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];

Poderia muito bem ser escrito como:

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];

Apenas para acelerar as coisas "o código está sendo executado ... :)

Continuação ...