Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think what you really want is as follow: 1.Label's top is 100 from its superView and its bottom is 68 from its superView 2.In 4" display, its size is 200x400 with ratio .5 3.In 3.5" display, its size is 312x624 with ratio .5</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; // create search bar CGRect frame = CGRectMake(60, 100, 200, 400); _label = [[UILabel alloc] initWithFrame:frame]; _label.backgroundColor = [UIColor blueColor]; [self.view addSubview:_label]; // layout search bar _label.translatesAutoresizingMaskIntoConstraints = NO; // height NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:_label attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationLessThanOrEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0 constant:400]; // width [_label addConstraint:constraint]; constraint = [NSLayoutConstraint constraintWithItem:_label attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:_label attribute:NSLayoutAttributeHeight multiplier:0.5 constant:0]; [_label addConstraint:constraint]; // vertical NSDictionary *views = NSDictionaryOfVariableBindings(_label, self.view); NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-100-[_label]-68-|" options:0 metrics:nil views:views]; [self.view addConstraints:constraints]; // horizontal constraint = [NSLayoutConstraint constraintWithItem:_label attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]; [self.view addConstraint:constraint]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload