IOS 学习之路(一) 徒手写界面(1)
来源:互联网 发布:日服lol mac要加速器嘛 编辑:程序博客网 时间:2024/05/16 02:49
感觉自己买的IOS书上面写的都是拖控件的方法写IOS界面
但是在实际的求职和工作中,拖控件的方法并不是很好用,或者说团队合作的情况下根本不能使用。
所以准备写一篇IOS 徒手写界面的指南吧,也算自己的学习心得。
我们准备写一个登入页面,大概样子如下:
那么我们开始吧!
@interface ViewController ()@property (nonatomic,strong) UILabel * PhoneLable; //手机@property (nonatomic,strong) UILabel * PasswordLable; //密码@property (nonatomic,strong) UITextField * PhoneTextField;@property (nonatomic,strong) UITextField * PwdTextField;@property (nonatomic,strong) UILabel * oneLabel;@property (nonatomic,strong) UILabel * towLabel;@property (nonatomic,strong) UIButton * enterbtn;@property (nonatomic,strong) UILabel * ForgetPwdLabel;@property (nonatomic,strong) UILabel * RegistrationLabel;@end
声明控件
他和拖控件的代码差别是少了一个IBOutlet;
然后我们需要写控价的位置和属性
代码如下:
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. _PhoneLable = [[UILabel alloc]init]; _PhoneLable.frame = CGRectMake(30, 130, 45, 20); _PhoneLable.text = @"手机"; _PhoneLable.textColor = [UIColor whiteColor]; _PhoneLable.font = [UIFont systemFontOfSize:(17)]; _PhoneTextField = [[UITextField alloc]init]; _PhoneTextField.frame = CGRectMake(80, 130, 270, 20); _oneLabel = [[UILabel alloc]init]; _oneLabel.frame = CGRectMake(30, 159, 315, 1); _oneLabel.backgroundColor = [UIColor whiteColor]; _PasswordLable = [[UILabel alloc]init]; _PasswordLable.frame = CGRectMake(30, 190, 45, 20); _PasswordLable.text = @"密码"; _PasswordLable.textColor = [UIColor whiteColor]; _PasswordLable.font = [UIFont systemFontOfSize:(17)]; _PwdTextField = [[UITextField alloc]init]; _PwdTextField.frame = CGRectMake(80, 190, 270, 20); _towLabel = [[UILabel alloc]init]; _towLabel.frame = CGRectMake(30, 220, 315, 1); _towLabel.backgroundColor = [UIColor whiteColor]; _enterbtn = [[UIButton alloc]init]; _enterbtn.backgroundColor = [UIColor redColor]; _enterbtn.frame = CGRectMake(30, 255, 315, 45); _enterbtn.titleLabel.font = [UIFont systemFontOfSize:(20)]; _enterbtn.titleLabel.textColor = [UIColor whiteColor]; [_enterbtn setTitle:@"登录" forState:UIControlStateNormal]; [_enterbtn.layer setCornerRadius:10.0]; _ForgetPwdLabel = [[UILabel alloc]init]; _ForgetPwdLabel.frame = CGRectMake(23, 630, 60, 15); _ForgetPwdLabel.text = @"忘记密码?"; _ForgetPwdLabel.textColor = [UIColor whiteColor]; _ForgetPwdLabel.font = [UIFont systemFontOfSize:(10)]; _RegistrationLabel = [[UILabel alloc]init]; _RegistrationLabel.frame = CGRectMake(300, 630, 60, 15); _RegistrationLabel.text = @"注册账号"; _RegistrationLabel.textColor = [UIColor whiteColor]; _RegistrationLabel.font = [UIFont systemFontOfSize:(10)]; self.view.backgroundColor = [UIColor grayColor]; [self.view addSubview:self.PhoneLable]; [self.view addSubview:self.PhoneTextField]; [self.view addSubview:self.oneLabel]; [self.view addSubview:self.PasswordLable]; [self.view addSubview:self.PwdTextField]; [self.view addSubview:self.towLabel]; [self.view addSubview:self.enterbtn]; [self.view addSubview:self.ForgetPwdLabel]; [self.view addSubview:self.RegistrationLabel];}
写好的界面如下
alloc是向系统申请内存,int是一个初始化方法。
CGRectMake 是来控制控件的位置。它有四个值 分别是 x,y,控件的宽度,控件的高度。 原点是iphone的 最左上角。
addSubview是把空间放到View上面。
这样就可以把控件显示在view上面了
但是这个不是自适应的方法,还有代码笔记繁琐
下一次我会使他变好看一点,使用懒加载。
等待徒手写界面(2)吧!
0 0
- IOS 学习之路(一) 徒手写界面(4)控件(1)
- IOS 学习之路(一) 徒手写界面(1)
- IOS 学习之路(一) 徒手写界面(4)控件(2)Label
- IOS 学习之路(一) 徒手写界面(2)自适应和懒加载
- IOS 学习之路(一) 徒手写界面(3)使用框架
- 徒手hypervisor(一)
- 如何利用opencv c++徒手写BP神经网络识别数字(一)前言及准备
- Unity3D学习之界面编辑器(一)
- latex徒手写论文之小白篇
- 徒手hypervisor(二)
- 徒手hypervisor(三)
- IOS学习之——界面2传值到界面1(代理方法)
- IOS学习笔记——基础界面 (一)
- iOS学习之路(三)--界面篇
- Unity3D学习 愤怒的小鸟之Logo界面(一)
- Unity3d 学习界面 之 工程浏览器 (Project Browser)(一)
- Linux内核之——C语言“徒手”写内存!
- 徒手写uboot_1
- sitemesh装饰器
- 声明与函数、函数指针
- 初识Postman
- L3-003. 社交集群
- 笔试题目(1)
- IOS 学习之路(一) 徒手写界面(1)
- 6月英语
- 欢迎使用CSDN-markdown编辑器
- C#反射中Assembly.Load及Assembly.Load.CreateInstance方法介绍
- Hnadler机制
- spring的aop,为一个service添加一个一个逻辑
- 杀毒软件的简单实现
- 图解Linux命令之--ln命令
- 深入浅出ShellExecute