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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -