You can set the height and width visually like this.

    NSArray *foo1 = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[clearSearchButton(==searchBar)]" options:0 metrics:nil views:views];
    NSArray *foo2 = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[clearSearchButton(==searchBar)]" options:0 metrics:nil views:views];

You can set it programmatically with a constraint like this

 NSLayoutConstraint *foo = [NSLayoutConstraint constraintWithItem:self.clearSearchButton
                                                                   attribute:NSLayoutAttributeHeight
                                                                   relatedBy:NSLayoutRelationEqual
                                                                      toItem:self.searchBar
                                                                   attribute:NSLayoutAttributeHeight
                                                                  multiplier:1
                                                                    constant:0];

    [self.view addConstraint:foo];

Or You can set it to a specific height like this.

    [self.clearSearchButton addConstraint:[NSLayoutConstraint constraintWithItem:self.clearSearchButton
                                                     attribute:NSLayoutAttributeHeight
                                                     relatedBy:NSLayoutRelationEqual
                                                        toItem:nil
                                                     attribute: NSLayoutAttributeNotAnAttribute
                                                    multiplier:1
                                                      constant:20]];
Advertisements