
Xcode中怎么做登陆界面
现在xcode新建的项目都是自带故事板的,操作不是很方便,来把它改成说写代码
打开AppDelegate.h文件,添加以下代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.rootViewController=[[ViewController alloc] init]; [self.window makeKeyAndVisible]; return YES; }
到此就完成了手写代码的第一步。
添加输入框和按钮
在ViewController.h中添加以下代码
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic,strong) UITextField *account;
@property (nonatomic,strong) UITextField *password;
@property (nonatomic,strong) UIButton *loginButton;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor colorWithRed:51/255.0 green:204/255.0 blue:255/255.0 alpha:1]];
_account=[[UITextField alloc] initWithFrame:CGRectMake(20, 200, self.view.frame.size.width-40, 50)];
_account.backgroundColor=[UIColor whiteColor];
_account.placeholder=[NSString stringWithFormat:@"Email"];
[self.view addSubview:_account];
_password=[[UITextField alloc] initWithFrame:CGRectMake(20, 260, self.view.frame.size.width-40, 50)];
_password.backgroundColor=[UIColor whiteColor];
_password.placeholder=[NSString stringWithFormat:@"Password"];
[self.view addSubview:_password];
_loginButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[_loginButton setFrame:CGRectMake(20, 320, self.view.frame.size.width-40, 50)];
[_loginButton setTitle:@"Login" forState:UIControlStateNormal];
[_loginButton setBackgroundColor:[UIColor colorWithRed:51/255.0 green:102/255.0 blue:255/255.0 alpha:1]];
[_loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.view addSubview:_loginButton];
}
@end
运行一下看看效果

2024-09-19 广告
2014-09-30
广告 您可能关注的内容 |