What is like linear layout in ios

I have many components in my view controller, and I want to combine them in one object to scroll them together, what is the procedure for its execution (e.g. linearlayout in android), but I need it in IOS.

+7
source share
7 answers

iOS9 introduced something similar to LinearLayout: UiStackView

Watch this video from WWDC 2015: https://developer.apple.com/videos/wwdc/2015/?id=218

+8
source

Apple doesn't provide a linear container but you can use XHFLinearView on github

Usage example:

XHFLinearView *linearView=[[XHFLinearView alloc]initWithFrame:self.view.bounds]; [self.view addSubview:linearView]; //init linear view content views [linearView.itemSource addObject:XHFLinearViewUnitMake(someView, XHFMarginMake(0, 0, 0, 0))]; //force layout linear view [linearView needLayout]; //insert a view with animation [linearView insertItem:someView margin:XHFMarginMake(0, 0, 0, 0) atIndex:0 withAnimation:XHFLinearItemAnimationFade]; //replace a view with animation [linearView replaceItem:someView withNewItem:newView withAnimation:XHFLinearItemAnimationFade]; //resize a view with animation someView.frame=xxx; [linearView needLayoutForItem:someView]; //remove a view with animation [linearView removeItemByIndex:0 withAnimation:XHFLinearItemAnimationFade]; 
+1
source

Layoutmanager

First of all, what you are looking for is a declarative API for layouts. I think that many people who come from other languages ​​/ platforms miss this. IOS has several other approaches, such as layout restrictions or automation. However, this is not suitable for all use cases.

Layout Layouts

I would suggest exploring some of the libraries existing in CocoaPods . It is easy to install and start with. I would like to mention CSLinearLayoutView, which is pretty simple. Even I support the smaller MKLayoutLibrary project, which is available through CocoaPods . This is a more compressive device that also provides a linear, stackable and simple flow arrangement.

Clean solution

However, if you really want to delve deeply into the topic of layouts, I recommend playing with UICollectionView and its layout customization capabilities.

Note that declarative solutions do not work for a huge number of elements or endless scrollable layouts. If you want to do this, check out the custom UICollectionView layouts .

+1
source

In iOS, this layout is not available in iOS. Each component that you add to the view will be displayed based on its frame (not sequentially).

You can use UIScrollView for this .

Check out this tutorial How to use UIScrollView

0
source

You will probably have to work a bit with iOS. You can add all your views to the UIScrollView , however you need to set the contentSize UIScrollView accordingly. Essentially, for N elements, the scroll width will be:

 scrollView.contentSize = CGSizeMake(N * itemWidth + (N - 1) * itemPadding, itemHeight); 

Then you need to set the frame for each UIView so that its x coordinate is suitable, and add it to the UIScrollView :

 for (int i = 0; i < views.count; i++) { UIView *view = [views objectAtIndex:i]; view.frame = CGRectMake(i * itemWidth + i * itemPadding, view.frame.origin.y, view.frame.size.width, view.frame.size.height); [scrollView addSubview:view]; } 

If you need something more complex than a simple linear layout, check out the UICollectionView .

0
source

I just wrote a widget called AutoLinearLayoutView that can be extracted from Github .

It is fully based on automatic layout and supports iOS 7 + . According to your requirement, the sample project perfectly demonstrates a dozen widgets that are wrapped in a linear layout view, and the linear layout view is placed in UIScrollView.

0
source

Each component is like a uiview in ios. so you can put all components in a UIView, for example

 [containerView addSubView:YourComponent1]; [containerView addSubView:YourComponent2]; [containerView addSubView:YourComponent3]; 

then you can add this to your UIScrollView

-one
source

All Articles