Einführung in UIKit: UIView und UIViewController
Standard-Typen CoreGraphics, UIKit
-
CoreGraphics-Datentypen sind
C structs, keineObjective-CObjekte:CGFloat x = 0, y = 0, width = 100, height = 100; CGPoint point = CGPointMake(x, y); CGRect rect = CGRectMake(x, y, width, height); CGRect rectZero = CGRectZero; CGSize size = CGSizeMake(width, height);
-
Farben in UIKit:
[UIColor colorWithRed:1.0f green:0.0f blue:0.0f alpha:1.0f]; [UIColor colorWithRed:130.0f/255.0f green: 10.0f/255.0f blue: 90.0f/255.0f alpha: 1.0f]; [UIColor redColor];
Auszug UIView Klassenhierarchie
Beispiel UIView
UIView* view = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, height)];
[parentView addSubview:view];
[view release];
UIView Frames und Bounds
UIView.framebestimmt die Position und Größe des Views relativ zu dem Koordinatensystem des Parent-Views.UIView.boundsbestimmt die Position und Größe des Views relativ zum eigenen Koordinatensystem (die Größe entspricht der Größe desframe, die Position ist typischerweise(0,0), kann aber verschoben werden).- Der
framedesUIWindowist die gesamte Bildschirmfläche inkl. Status-Bar. Einenframeohne Status-Bar erhält man mit[[UIScreen mainScreen] applicationFrame].
Beispiel UILabel
UILabel* aLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
aLabel.text = @"Hello world";
[parentView addSubview:aLabel];
[aLabel release];
Beispiel UIButton
UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(x, y, width, height);
NSString* title = [NSString stringWithFormat:@"1 + 1 is %i", 1 + 1];
[button setTitle:title forState:UIControlStateNormal];
[self.view addSubview:button];
UIViewController
- Ein
UIViewControllerist für die Verwaltung eines Screens einer iPhone-Anwendung zuständig. - Inhalte können aus einem Interface Builder-NIB geladen werden (
initWithNibName:@"MyView" bundle:nil+viewDidLoad) - Oder programmatisch erzeugt werden (
initWithNibName:nil bundle:nil+loadView)

