.AppDelegate.m
#import “OneViewController.h”
//一打开就运行的
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
OneViewController *oneController = [[OneViewController alloc] init];
[self.window setRootViewController:oneController];
[self.window makeKeyAndVisible];
return YES;
}
.OneViewController.m
#import “TwoViewController.h”
-(void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor orangeColor];
[self OneButton];
}
//添加button
#pragma mark – Button
-(void)OneButton
{
UIButton *myButton = [[UIButton alloc] init];
myButton.frame = CGRectMake(,300,90,35);
myButton.backgroundColor = [UIColor grayColor];
[myButton setTitle:”确定” forState:UIControlStateNormal];
[self.view.addSubview:myButton];
//addSubview: 添加一个视图对接收者的子视图列表。
[myButton addTarget:self action:@selector(ClickMyButton) forControlEvents:UIControlEventTouchUpInside];
//addTarget: 将目标对象和动作方法与控制关联。
}
//Button点击事件
#pragma mark - Button
-(void)ClickButton
{
TwoViewController *two = [[TwoViewController alloc] init];
//跳转到下一页面
[self presentViewController:two animated:YES completion:nil];
}
//跳转到上一页面
[self dismissViewControllerAnimated:YES completion:nil];
.Label
[self label1];
-(void)Label
{
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(,,,)];
label1.backgroundColor = [UIColor whiteColor];
label1.text = @”显示”;
label1.textColor = [UIColor blackColor];
[self.view addSubview:label1];
}
.TextField
[self _text];
-(void)TextField
{
_text = [[UITextField alloc] initWithFrame:CGRectMake(,,,)];
_text.borderStyle = UITextBorderStyleRoundedRect;
_text.backgroundColor = [UIColor whiteColor];
_text.placeholder = @”请输入密码”;
_text.textColor = [UIColor blackColor];
_text.keyboardType = UIKeyboardTypeDefault;
_text.returnKeyType = UIReturnKeyGo;
[self.view addSubview:_text];
}