1.Setting the background Color of a View Controller:
self.view.backgroundColor = [UIColor blueColor]
2.Adding a label
UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake(50, 50, 150, 150)];
[label setText:@"I am a label"];
label.textAlignment = NSTextAlignmentCenter;
[self.view addSubview: label];
3.Adding a textfield
UITextField *textField = [[UITextField alloc] initWithFrame: CGRectMake(50, 100, 200, 200)];
[textField setText:@"I am a textField"];
[self.view addSubview: textField];
4.Adding a TextView
UITextView *textView = [[UITextView alloc] initWithFrame: CGRectMake(50, 100, 200, 200)];
[textView setText:@"I am a TextView"];
[self.view addSubView: textView];
5.Get the size of current iOS device (iPhone):
CGFloat w = [UIScreen mainScreen].bounds.size.width;
CGFloat h = [UIScreen mainScreen].bounds.size.height;
You can print w, h using NSLog:
NSLog(@"The current iOS device has a screen size of width: %f and height: %f", w, h);
网友评论