IOS 学习之路(一) 徒手写界面(1)
2016-06-30 22:00
465 查看
感觉自己买的IOS书上面写的都是拖控件的方法写IOS界面
但是在实际的求职和工作中,拖控件的方法并不是很好用,或者说团队合作的情况下根本不能使用。
所以准备写一篇IOS 徒手写界面的指南吧,也算自己的学习心得。
我们准备写一个登入页面,大概样子如下:
那么我们开始吧!
声明控件
他和拖控件的代码差别是少了一个IBOutlet;
然后我们需要写控价的位置和属性
代码如下:
写好的界面如下
alloc是向系统申请内存,int是一个初始化方法。
CGRectMake 是来控制控件的位置。它有四个值 分别是 x,y,控件的宽度,控件的高度。 原点是iphone的 最左上角。
addSubview是把空间放到View上面。
这样就可以把控件显示在view上面了
但是这个不是自适应的方法,还有代码笔记繁琐
下一次我会使他变好看一点,使用懒加载。
等待徒手写界面(2)吧!
但是在实际的求职和工作中,拖控件的方法并不是很好用,或者说团队合作的情况下根本不能使用。
所以准备写一篇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)吧!
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- flex 控件的重要属性
- 学习Winform文本类控件(Label、Button、TextBox)
- Delphi控件ListView的属性及使用方法详解
- web下载的ActiveX控件自动更新
- WinForm实现按名称递归查找控件的方法
- C#中父窗口和子窗口之间控件互操作实例
- C#编写ActiveX网页截图控件
- Android编程之Button控件用法实例分析
- Android控件之CheckBox、RadioButton用法实例分析
- 在Android开发中使用自定义组合控件的例子
- 一款超酷的Android自定义加载控件
- Android重写View实现全新的控件
- MFC中动态创建控件以及事件响应实现方法