ios - Centering a container view -
//i have 3 containers in screen. top/ middle / bottom (i've added middle's codes here)
- (void)initlayoutconstrains { [self initmiddlelayoutcontainerconstraint]; nsmutablearray *constraints = [[nsmutablearray alloc] init]; nsdictionary *viewsdictionary = nsdictionaryofvariablebindings(_topcontainerbar, _bottomcontainerbar, _middlecontainerbar); [constraints addobjectsfromarray:[nslayoutconstraint constraintswithvisualformat:@"|-(>=20)-[_middlecontainerbar(==200)]-(>=20)-|" options: nslayoutformatalignallcenterx | nslayoutformatalignallcentery metrics:nil views:viewsdictionary]];
edit: have not time here temporary solution came with:
cgfloat testviewheight = 200; nsdictionary *metrics = @{ @"testviewy": @(self.view.frame.size.height / 2 - testviewheight / 2), @"testviewheight":@(testviewheight)}; [constraints addobjectsfromarray:[nslayoutconstraint constraintswithvisualformat:@"v:|-testviewy-[testview(==testviewheight)]" options: kniloptions metrics:metrics views:viewsdictionary]]; [constraints addobjectsfromarray:[nslayoutconstraint constraintswithvisualformat:@"h:|[testview]|" options:kniloptions metrics:nil views:viewsdictionary]];
Comments
Post a Comment