美文网首页
纯代码写UI

纯代码写UI

作者: Bakergus | 来源:发表于2019-01-30 10:51 被阅读0次

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

相关文章

网友评论

      本文标题:纯代码写UI

      本文链接:https://www.haomeiwen.com/subject/jdmqsqtx.html