新建⼀个工程,创建一个与window等⼤的视图containerView,然后用不同颜色的视图拼出一个登录界面。(设置成手动释放内存MRC形式)
1.设置透明度;
2.插入文本;
3.设置文本阴影颜色,大小;
4.设置输入框.
//1.创建一个与window等⼤的视图containerView(灰色)
UIView *containerView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
containerView.backgroundColor = [UIColor grayColor];
[self.window addSubview:containerView];
[containerView release];
//用不同颜色的视图拼出一个登录界面
//2.设置2个红色视图的起始点,长度,宽度
UIView *redViewAbove = [[UIView alloc] initWithFrame:CGRectMake(20, 120, 120, 50)];
redViewAbove.backgroundColor = [UIColor redColor];
[self.window addSubview:redViewAbove];
[redViewAbove release];
UIView *redViewBelow = [[UIView alloc] initWithFrame:CGRectMake(20, 200, 120, 50)];
redViewBelow.backgroundColor = [UIColor redColor];
[self.window addSubview:redViewBelow];
[redViewBelow release];
//3.设置2个蓝色视图的起始点,长度,宽度
UIView *blueViewAbove = [[UIView alloc] initWithFrame:CGRectMake(170, 120, 180, 50)];
blueViewAbove.backgroundColor = [UIColor blueColor];
[self.window addSubview:blueViewAbove];
[blueViewAbove release];
UIView *blueViewBelow = [[UIView alloc] initWithFrame:CGRectMake(170, 200, 180, 50)];
blueViewBelow.backgroundColor = [UIColor blueColor];
[self.window addSubview:blueViewBelow];
[blueViewBelow release];
//4.设置3个绿色视图的起始点,长度,宽度
UIView *greenViewLeft = [[UIView alloc] initWithFrame:CGRectMake(20, 280, 90, 50)];
greenViewLeft.backgroundColor = [UIColor greenColor];
[self.window addSubview:greenViewLeft];
[greenViewLeft release];
UIView *greenViewMiddle = [[UIView alloc] initWithFrame:CGRectMake(140, 280, 90, 50)];
greenViewMiddle.backgroundColor = [UIColor greenColor];
[self.window addSubview:greenViewMiddle];
[greenViewMiddle release];
UIView *greenViewRight = [[UIView alloc] initWithFrame:CGRectMake(260, 280, 90, 50)];
greenViewRight.backgroundColor = [UIColor greenColor];
[self.window addSubview:greenViewRight];
[greenViewRight release];
//5.设置各个视图的透明度
containerView.alpha = 0.5;
redViewAbove.alpha = 0.2;
redViewBelow.alpha = 0.2;
blueViewAbove.alpha = 0.2;
blueViewBelow.alpha = 0.2;
greenViewLeft.alpha = 0.2;
greenViewMiddle.alpha = 0.2;
greenViewRight.alpha = 0.2;
//6.插入文本
UILabel *userNameLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(30, 120, 120, 50)];
userNameLabel1.text = @"请输入用户名";
[containerView addSubview:userNameLabel1];
[userNameLabel1 release];
UILabel *userNameLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(35, 200, 120, 50)];
userNameLabel2.text = @"请输入密码";
[containerView addSubview:userNameLabel2];
[userNameLabel2 release];
UILabel *userNameLabel3 = [[UILabel alloc] initWithFrame:CGRectMake(48, 280, 90, 50)];
userNameLabel3.text = @"登陆";
[containerView addSubview:userNameLabel3];
[userNameLabel3 release];
UILabel *userNameLabel4 = [[UILabel alloc] initWithFrame:CGRectMake(168, 280, 90, 50)];
userNameLabel4.text = @"注销";
[containerView addSubview:userNameLabel4];
[userNameLabel4 release];
UILabel *userNameLabel5 = [[UILabel alloc] initWithFrame:CGRectMake(288, 280, 90, 50)];
userNameLabel5.text = @"退出";
[containerView addSubview:userNameLabel5];
[userNameLabel5 release];
//7.设置文本阴影颜色
userNameLabel1.shadowColor = [UIColor blackColor];
userNameLabel2.shadowColor = [UIColor blackColor];
userNameLabel3.shadowColor = [UIColor blackColor];
userNameLabel4.shadowColor = [UIColor blackColor];
userNameLabel5.shadowColor = [UIColor blackColor];
//8.设置文本阴影大小
userNameLabel1.shadowOffset = CGSizeMake(1, 1);
userNameLabel2.shadowOffset = CGSizeMake(1, 1);
userNameLabel3.shadowOffset = CGSizeMake(1, 1);
userNameLabel4.shadowOffset = CGSizeMake(1, 1);
userNameLabel5.shadowOffset = CGSizeMake(1, 1);
//9.设置输入框
UITextField *userNameTextField1 = [[UITextField alloc] initWithFrame:CGRectMake(170, 120, 180, 50)];
userNameTextField1.borderStyle = UITextBorderStyleRoundedRect;
userNameTextField1.placeholder = @"⼿机号/邮箱/QQ号";
[containerView addSubview:userNameTextField1];
[userNameTextField1 release];
UITextField *userNameTextField2 = [[UITextField alloc] initWithFrame:CGRectMake(170, 200, 180, 50)];
userNameTextField2.borderStyle = UITextBorderStyleRoundedRect;
userNameTextField2.placeholder = @"数字,下划线,英文";
[containerView addSubview:userNameTextField2];
[userNameTextField2 release];
//效果图: