2018-02-27 SDAutoLayout的简单使用

import "SDAutoLayout.h"

SDAutoLayout的使用
自写button


2018-02-27 SDAutoLayout的简单使用_第1张图片
自定义button.png
- (void)addSubView
{
    self.chooseButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.chooseButton.layer.borderWidth = 1;
    self.chooseButton.layer.borderColor = JMColor(219, 219, 219).CGColor;
    [self.chooseButton addTarget:self action:@selector(ClickChooseButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.chooseButton setImage:[UIImage imageNamed:@"tabBar_service"] forState:UIControlStateNormal];
    self.chooseButton.titleLabel.font = [UIFont systemFontOfSize:20 *KScale];
//    button 的imageView
    self.chooseButton.imageView.sd_layout
    .heightIs(68 *KScale)
    .widthIs(71 *KScale)
    .leftSpaceToView(self.chooseButton, 65 *KScale)
    .topSpaceToView(self.chooseButton, 40 *KScale);
//    button的 title
    [self.chooseButton setTitle:@"选择联系人" forState:UIControlStateNormal];
    [self.chooseButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    self.chooseButton.titleLabel.sd_layout
    .widthIs(140 *KScale)
    .heightIs(40 *KScale)
    .leftSpaceToView(self.chooseButton, 45 *KScale)
    .topSpaceToView(self.chooseButton.imageView, 17 *KScale);
    
    [self.contentView addSubview:self.chooseButton];
    
    self.chooseButton.sd_layout
    .rightSpaceToView(self.contentView, 20 *KScale)
    .topSpaceToView(self.contentView, 20 *KScale)
    .heightIs(200 *KScale)
    .widthIs(200 *KScale);
    
    UIView * lineView = [[UIView alloc]init];
    lineView.backgroundColor = JMColor(219, 219, 219);
    [self.contentView addSubview:lineView];
    lineView.sd_layout
    .leftSpaceToView(self.contentView, 30 * KScale)
    .centerYEqualToView(self.contentView)
    .heightIs(1)
    .rightSpaceToView(self.chooseButton, 0);
    
    //收货人
    CGFloat leftWidth = (self.contentView.frame.size.width - 101 * KScale) * 0.35;
    CGFloat leftHeight = 101 * KScale;
    UILabel * label  = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, leftWidth, leftHeight)];
    label.textColor = [UIColor blackColor];
    label.textAlignment = NSTextAlignmentLeft;
    label.font = [UIFont systemFontOfSize:32 * KScale];
    label.text = @"收货人:";
    
    self.nameTextField = [[UITextField alloc] init];
    self.nameTextField.leftView = label;
    self.nameTextField.font = [UIFont systemFontOfSize:30 *KScale];
    self.nameTextField.leftViewMode = UITextFieldViewModeAlways;
    self.nameTextField.textAlignment = NSTextAlignmentLeft;
    self.nameTextField.borderStyle = UITextBorderStyleLine;
    self.nameTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    self.nameTextField.textColor = [UIColor blackColor];
    self.nameTextField.delegate = self;
    self.nameTextField.returnKeyType = UIReturnKeyDone;
    self.nameTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
    self.nameTextField.autocorrectionType = UITextAutocorrectionTypeNo;
    self.nameTextField.keyboardType = UIKeyboardTypeDefault;
    [self.contentView addSubview:self.nameTextField];
    
    self.nameTextField.sd_layout
    .leftSpaceToView(self.contentView, 30 *KScale)
    .topEqualToView(self.chooseButton)
    .rightSpaceToView(self.chooseButton, 0)
    .heightRatioToView(self.chooseButton, 0.5);
    
    
    //手机号码
    UILabel * label1  = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, leftWidth, leftHeight)];
    label1.textColor = [UIColor blackColor];
    label1.textAlignment = NSTextAlignmentLeft;
    label1.font = [UIFont systemFontOfSize:32 * KScale];
    label1.text = @"手机号码:";
    
    self.phoneNumberTextField = [[UITextField alloc] init];
    self.phoneNumberTextField.leftView = label1;
    self.phoneNumberTextField.font = [UIFont systemFontOfSize:30 *KScale];
    self.phoneNumberTextField.leftViewMode = UITextFieldViewModeAlways;
    self.phoneNumberTextField.textAlignment = NSTextAlignmentLeft;
    self.phoneNumberTextField.borderStyle = UITextBorderStyleLine;
    self.phoneNumberTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    self.phoneNumberTextField.textColor = [UIColor blackColor];
    self.phoneNumberTextField.delegate = self;
    self.phoneNumberTextField.returnKeyType = UIReturnKeyDone;
    self.phoneNumberTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
    self.phoneNumberTextField.autocorrectionType = UITextAutocorrectionTypeNo;
    self.phoneNumberTextField.keyboardType = UIKeyboardTypeDefault;
    [self.contentView addSubview:self.phoneNumberTextField];

    self.phoneNumberTextField.sd_layout
    .leftEqualToView(self.nameTextField)
    .rightEqualToView(self.nameTextField)
    .heightRatioToView(self.chooseButton, 0.5)
    .topSpaceToView(self.nameTextField, 0);
    
    
}

你可能感兴趣的:(2018-02-27 SDAutoLayout的简单使用)