Reputation: 9461
How to implement Grid layout for ios? There are similar layouts: <Grid>
in windows xaml
and <GridLayout>
in android, but I failed to find any resource which covers how to implement similar thing in ios.
In brief: there are should be so called "Grid" in which I specify how many rows and cells are there and then I can specify that some particular control (for ex. TextView
) should start at x
column and span w
columns, start at y
row and span h
rows.
Update: don't confuse GridControl
with GridLayout
, an example of GridLayout
:
Upvotes: 2
Views: 7830
Reputation: 9461
I was able to implement GridLayout with help of the following blog article: https://web.archive.org/web/20170620013903/http://blog.stablekernel.com/creating-a-custom-uicollectionviewlayout
In brief I had to implement my own UICollectionViewLayout, but I didn't need the complexity as it was presented in the article.
The problem with this solution is cell reusing, which I don't need and there is no way to switch it off.
Upvotes: 2
Reputation: 9461
One more way to implement it is to inherit from UIView and override LayoutSubviews method and set children Frame manually.
Upvotes: 0
Reputation: 9461
Another option is to find out how xamarin implemented GridLayout and try to reproduce it. https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Core/GridCalc.cs
Upvotes: 0
Reputation: 3405
Use a UICollectionView for Grid Layout. Check this answer which shows the integration of UICollectionView
in details
For such a layout also, you need to use collectionView
itself, but use the sizeForItemAtIndexPath
dataSource properly. Check this answer. Also try to customize UICollectionViewFlowLayout
Also this is an awesome library which also do the same thing for you
Upvotes: 2
Reputation: 913
Use collectionviews to write grid layout
https://developer.apple.com/documentation/uikit/uicollectionview
Upvotes: 3