1. 程式人生 > >【iOS開發】---- iOS自動佈局(二)

【iOS開發】---- iOS自動佈局(二)

- (NSArray *) emailTextFieldConstraints
{
    NSMutableArray *result = [[NSMutableArray alloc] init];
    NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(_textFieldEmail);//??
    [result addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:KEmailTextFieldHorizontal
                                                                        options:0
                                                                        metrics:nil
                                                                          views:viewsDictionary]];
    [result addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:KEmailTextFieldVertical
                                                                        options:0
                                                                        metrics:nil
                                                                          views:viewsDictionary]];

    return [NSArray arrayWithArray:result];
    
}

-(NSArray *)confirmEmailTextFieldConstraints
{
    NSMutableArray *result = [[NSMutableArray alloc] init];
    NSDictionary *viewDictionary = NSDictionaryOfVariableBindings(_textFieldConfirmEmail,_textFieldEmail);
    [result addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:KConfirmEmailHorizontal
                                                                        options:0
                                                                        metrics:nil
                                                                          views:viewDictionary]];
    [result addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:KConfirmEmailVertical
                                                                        options:0
                                                                        metrics:nil
                                                                          views:viewDictionary]];
    return [NSArray arrayWithArray:result];
}
- (NSArray *) registerButtonConstraints{
    NSMutableArray *result = [[NSMutableArray alloc] init];
    NSDictionary *viewsDictionary =
    NSDictionaryOfVariableBindings(_registerButton, _textFieldConfirmEmail);
    [result addObject:
     [NSLayoutConstraint constraintWithItem:self.registerButton
                                  attribute:NSLayoutAttributeCenterX
                                  relatedBy:NSLayoutRelationEqual
                                     toItem:self.view
                                  attribute:NSLayoutAttributeCenterX
                                 multiplier:1.0f
                                   constant:0.0f]
     ];
    [result addObjectsFromArray:
     [NSLayoutConstraint constraintsWithVisualFormat:KRegisterVertical
                                             options:0
                                             metrics:nil
                                               views:viewsDictionary]
     ];
    return [NSArray arrayWithArray:result];
}
- (NSArray *) constraints
{
    NSMutableArray *result = [[NSMutableArray alloc] init];
    [result addObjectsFromArray:[self emailTextFieldConstraints]];
    [result addObjectsFromArray:[self confirmEmailTextFieldConstraints]];
    [result addObjectsFromArray:[self registerButtonConstraints]];
    return [NSArray arrayWithArray:result];
}