The first use of the VFL language to achieve automatic layout, one or two control is OK, more than a few controls can not tolerate.
_backgroundimageview = [[Uiimageview alloc] init]; _backgroundimageview.backgroundcolor = [Uicolor Clearcolor]; _backgroundimageview.translatesautoresizingmaskintoconstraints = NO; [Self addsubview:_backgroundimageview]; nsmutablearray* contraints = [Nsmutablearray new]; [Contraints addobjectsfromarray:[nslayoutconstraint constraintswithvisualformat:@ "H:|-0-[_backgroundImageView]-0 -|" options:0 Metrics:nil Views:nsdictionaryofvar Iablebindings (_backgroundimageview)]; [Contraints addobjectsfromarray:[nslayoutconstraint constraintswithvisualformat:@ "V:|-0-[_backgroundImageView]-0 -|" options:0 Metrics:nil Views:nsdictionaryofvariablebindings (_backgroundimageview)]; [Self addconstraints:contraints];
And then I found out that masonry is now the way to automate layout:
_scrollview = [[Uiscrollview alloc] init]; _scrollview.pagingenabled = YES; _scrollview.backgroundcolor = [Uicolor clearcolor]; [Self addsubview:_scrollview]; [_scrollview makeconstraints:^ (Masconstraintmaker *make) { make.left.equalTo (0); Make.right.equalTo (0); Make.top.equalTo (0); Make.bottom.equalTo (0); }];
iOS Auto layout