I'm using PureLayout library. Github
I've UIScrollView
as a fullscreen container.
As a simple example, I've a UIView(0,0,100,50). I want to pin this view's right edge to right edge of UIScrollView
.
I'm doing it this way:
UIScrollView *sv = [UIScrollView newAutoLayoutView];
sv.alwaysBounceHorizontal = YES;
[self.view addSubview:sv];
[sv autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero];
UIView *v = [UIView newAutoLayoutView];
v.backgroundColor = [UIColor grayColor];
[v autoSetDimensionsToSize:CGSizeMake(100, 50)];
[sv addSubview:v];
[v autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:15];
[v autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:15];
//[v autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:15]; // also tried this
I get result:
I know, I can create a UIView container with same width as UIScrollView
, and add it as subview
of scrollView
and put all custom views into this container, but I wonder why we can't do it with UIScrollView
directly.