Artikel Tagged 'CGFloat "

Objective-C: eine Alternative zur Verwendung CGRectMake

CGRectMake() ist eine Funktion (eigentlich ein Inline # define) verwendet eine Menge vor allem, wenn Sie Grafik-Objekte aus dem Code oder Benutzeroberfläche zu erstellen. o UIImageView . CGRectMake() restituisce una struct (struttura di tipo) CGRect : Seine Verwendung ist daher oft die Initialisierung Komponenten verbunden UIKit , sondern auch auf einfache UIView oder UIImageView . CGRectMake() gibt ein struct (Struktur-Typ) CGRect :

1
2
3
4
5
struct {CGRect
CGPoint Ursprungs;
CGSize Größe;
};
typedef struct CGRect CGRect;

: Die wiederum aus zwei verschiedenen struct zusammen CGPoint und CGSize :

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

/ * Größen. * /

struct {CGSize
CGFloat Breite;
CGFloat Höhe;
};
typedef struct CGSize CGSize;

. Das wiederum, wieder enthalten Typen CGFloat oder Typ float . Wenn wir analysieren den Code von CGRectMake () sind:

1
2
3
4
5
6
7
8
CG_INLINE CGRect
CGRectMake (CGFloat x, y CGFloat, CGFloat Breite, Höhe CGFloat)
{
CGRect rect;
y; rect.origin.x = x, y = rect.origin.y;
height; rect.size.width = width, height = rect.size.height;
Rückkehr rect;
}

Daraus folgt, dass dieses Stück 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: @ "Presse" Forst: UIControlStateNormal];
gbutton ] ; [MainWindow addSubview: gbutton];

Es könnte zu Recht geschrieben werden als:

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: @ "Presse" Forst: UIControlStateNormal];
gbutton ] ; [MainWindow addSubview: gbutton];

Nur um die Dinge zu beschleunigen "der Code ausgeführt wird ... :)

Fortsetzung ...


Stoppen SOPA