IOS 学习之路(一) 徒手写界面(1)

感觉自己买的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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值