I created a collection view custom cell like this:
on iPhone 6.
But when I run my app on iPhone 5 or 5se my cell is like this:
How can I fix this?
If you want a decent amount of control over the layout of your UICollectionView you should have your viewController (or whoever is the UICollectionViewDelegate) also conform to UICollectionViewDelegateFlowLayout. This will allow you to set cell size, margins, spacing between items, etc. It is a very easy way to make the cells dynamically sized or spaced. See Apple's docs for more specifications.
Related
I want to make a kind of grid layout (not scrollable) in an iOS app, similar to this:
I can do it using multiple UIView but that won't be a good solution. If I use `UICollectionView', I believe it will become scrollable? I want fixed grid items, which resize them according to screen size.
Any guidelines please?
Thanks!
You should use collection view with scrolling and bouncing disable.
It is all about your collectionview's flowlayout's item size.
You have to calculate item size receptively your screen's size.
And you can set that item size to flowlayout and can use that flowlayout with your collection view.
For example, You can refer this so post.
If you just want fixed 3x2 layout scaling to any screen size then multiple UIView is a good solution for this and exactly what you should do.
Also make a RestaurantView UIView subclass to configure and display the image/rating/title/description/etc details for each restaurant.
-
If you want the number of restaurants to change depending on screensize then use a UICollectionView with ResturantCollectionViewCell instead.
I have a requirement to show the Data in Linear Vertical List in iPhone and
in Collection/Grid in IPAD
In the iPhone, it should look like
But In Ipad, it should look like
I have already implemented in iPhone through table view but don't know how to show it as grid view in IPAD
Here are my questions
should I have to create the Separate view controller for Ipad if yes
then how can I define two view controller one for iPhone and other
for iPad
what is the best way to achieve this?
please help me I am trying to implement it but can not find any way.
(Note)Images are copied from Vimeo iTunes app https://itunes.apple.com/us/app/vimeo/id425194759?mt=8
You don't need to create two different controller's for IPAD and IPHONE. Just create one controller with UICollectionView and then use UICollectionViewFlowLayout for your UICollectionView to set layout of UICollectionView according to the device weather it is IPAD or IPHONE Try this solution if you have any doubt pls let us know.
Try this solution
UICollectionViewFlowLayout *collectionViewFlowLayout = [[UICollectionViewFlowLayout alloc] init];
[collectionViewFlowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
self.myCollectionView.collectionViewLayout = collectionViewFlowLayout;
Also you can use multiple properties of UICollectionViewFlowLayout.
Check this solution and let me know if it works for you.
Check these links for reference :
https://www.raywenderlich.com/136159/uicollectionview-tutorial-getting-started
https://www.raywenderlich.com/107439/uicollectionview-custom-layout-tutorial-pinterest
The way to do this is with Adaptive Layout and size classes in the storyboard. You don’t need to write any code at all, and you are also covered for multitasking/split-screen and future iOS devices of unknown dimensions. You can make any view appear or disappear according to weather the width is compact (like the iPhone) or regular (like the iPad). In the views inspector you can add a variation for compact width like this:
Adding a compact width variation to view
Click add variation and untick “installed”. Now that view will only be installed when the device has compact width. You can do this with a container view with an embed segue to a UITableViewController.
If you view the storyboard as an iPad ( by clicking the little icons at the bottom where it says “view as”) that view will disappear. Replace with another container view that segues to UICollectionViewController and do the same again, but this time add a variation with regular width.
Thats it.
(Sorry, I don't have enough points to show images)
Here is a Demo project that creates something like the layout and behaviour you want. All the action is in the storyboard, the view controllers are just skeletons.
According to Apple Documents:
If you want to specify different sizes for your cells, you must implement the collectionView:layout:sizeForItemAtIndexPath: method on the collection view delegate. You can use the provided index path information to return the size of the corresponding item. During layout, the flow layout object centers items vertically on the same line, as shown in Figure 3-2. The overall height or width of the line is then determined by the largest item in that dimension.
https://developer.apple.com/library/content/documentation/WindowsViews/Conceptual/CollectionViewPGforIOS/UsingtheFlowLayout/UsingtheFlowLayout.html#//apple_ref/doc/uid/TP40012334-CH3-SW1
Now I have a collection view with 2 columns and cells varying in height. The problem is that the smaller cell is centered with the taller cell on its left/right, but not float up with the cell under it floats up too.
How can I make that happen?
What I have:
What I want:
It seems like that I should subclass UICollectionViewFlowLayout, but how should I accomplish this?
The type of collection view layout you desire is called "waterfall layout". The implementation is a little bit tricky, since you need to override the basic behaviour of UICollectionViewFlowLayout.
I suggest you to take a look at this tutorial by Ray Wenderlich for building a waterfall layout from the ground, or - if you desire an already packed library - using a library on GitHub, like CHTCollectionViewWaterfallLayout, WaterfallCollectionView or CollectionViewWaterfallLayout
What you want to achieve is called "staggered layout". It was introduced by Pinterest in their iOS app.
You will need custom collection view layout, this tutorial will explain how. Alternatively, you can use one of the existing solutions, for example CHTCollectionViewWaterfallLayout.
I'm working on an app that includes the names of users with their icons under an image. I'm currently using collection view in order to distribute the names. I'm using this approach since each cell when clicked will be holding the user object. However, I'm having some layout issues when it's used (please check attached image). The spacing is unusual. The desired output is the cells having a certain spacing limit between them and if any cell cannot fit, will be placed on the other line. I tried using the delegate methods for spacing by setting it to 5 however it's not working (the cell's size will be dynamic). Should I subclass and create my own Collection view Layout ? if there is any other approach without using collection views please let me know. Thank you.
After creating a universal app on Xcode 6, I have managed to create a UI collection view which displays 2 cells in the width of an iPhone. However when viewed on iPad, it shows 4 cells with lots of padding around the cells.
How can i change the size of cells on an iPad so that 3 cells are shown with minimal padding. I want to leave the iPhone size alone.
So far i have used the storyboard to set the cell size. I have a added a custom cell size of 158pts by 158pts which works perfectly with iPhones. I cannot find this code in the Objective C code. How can I set an individual different size for iPad.
This is what it looks like on iPhone.
https://www.dropbox.com/s/md1sn4z3k78i5s1/iphone.png
and this is what it currently looks like on iPad. The wrong way.
https://www.dropbox.com/s/0x2n9i8v6gvlfnc/ipad.png
I want to get rid of the Grey padding and increase the cell sizes so there are only 3 cells with the same padding as on the iPhone version.
I am a real beginner so any help is much appreciated.
I am answering my own post as I believe that the only way to do this is to use a standard ViewController and place a UICollectionView on top. This way you can add different UICollectionViews for the different Size Classes on Xcode 6.
At this point you can set different sizes for cells on iPad size classes to iPhones ones.
There maybe an easier way to use a UICollectionViewController but i am unaware of it, please let me know below.
EDIT
I have since found out this can be completed using the UICollectionViewController by using constraints and by increasing the cell when used on iPads by code.