UIColecctionView with Sections [SWIFT] IOS - ios

Hi People (Sorry for my English)
I have a problem. I want to create the next UI
I have a UIViewController It has a UITableView with a custom cell. This Custom cell has a UIImage, UILabel and UICollectionView.
My Problem begin here, in the UICollectionView
My UICollectionView has UILabel that represent a Sub Title and several buttons. one Sub Title has many buttons.
I already made this UI. I got the size buttons I got the width screen and I calculated the quantity of buttons that I can put by row. I also calculated
the sum of heigh of the Sub Titles and rows buttons and I set UICollectionView heigh, because I need to see all the items inside it.
I think that can be improved, because my code result is very confused.
My button has a constant width. I want to set my UICollectionView for that it will has a title section and rows buttons and the buttons change the row when the remaining space in the row is minor to width button.
Thanks :]

Related

How to place UILabel exactly below UITableView?

I have UITableView with height of ≤500. Tableview data comes from database. Below UITableView, there is one label and two radio button. The problem is if data in the UITableView is less than its height, then it shows blank space between UITableView and those two radio button. I want to place those label and radio button exactly below tableview. How should I do this ?
This is how my tableview looks
If the table view's height does indeed vary depending on shown content, you could use UITableView's tableFooterView.
For a bit more context see this post for example.
Alternatively you could do this with basic auto-layout by tying your label and radio buttons (that you place as siblings of the table) vertically to the bottom of the table view.
I could also imagine that you may need a section footer. So you may want to have a look at that too.
If you want it to be scrollable, add it as the last row in your table view. You may also go with table view's footer.
If you want it to be sticky at the bottom in case of more rows, go with auto layouts. You may create outlet of table view's height constraint and adjust that accordingly depending on the number of rows. However, this approach is not appreciated.

Scrolling Views Along with Collection View Cells

On my view controller I have 1 collectionview underneath 2 views at the top of the view controller I set the collection views height based on the size of the views so the collectionview is big enough that it doesn't need to scroll. All 3 views are inside of a scrollview so that I can scroll the views and the collection cells seamlessly. This feels very inefficient but i can't think of another way of providing this sort of seamless scroll between the views and the collectionview. Is there something else I can do to achieve the same or at least similar result?
EDIT: https://gyazo.com/8e5febea0974b0e6e0660f1714d67cbc this will hopefully explain it better. label is the view inside of the scrollview above the collectionview and four buttons are collectionview cells. Now if I add 20 buttons instead of only 4 I can scroll the collection view but it won't scroll with the label. This might also help explain what I'm trying to achieve - http://jsfiddle.net/hDwPH/
Ignore This Dummy Code
From the screen shot, I assume that your view controller consists of
1 UILabel
Multiple UIButtons
Only 1 item per row
If so, you should consider using UITableView instead. The UILabel will be section header, The UIButtons will be the rows (UITableViewCell). So your UITableView consists of 1 section, 20 rows.
If you want your UILabel to float along with the UIButtons, set the
UITableView style to UITableViewStyleGrouped
If you want your UILabel to remain fixed, set the UITableView style to UITableViewStylePlain

Add button as last UICollectionViewCell if all cells do not fit

My UICollection view should have no more than two rows. If all cells do not fit, it should add "Show More" button as last cell. Cells have dynamic width and UICollectionView is non scrollable.
What are my options?
EDIT
I guess I should check if all cell fits into the screen, maybe using collectionView.visibleCells. If they do not fit, I should probably insert my "Show More" cell. Does this sound reasonable? Any other ideas?
Oh, and all cells have dynamic width.

How to make an effect of expandable UICollectionView cell in iOS

I have a collection view 3x3.
Item (collection cell) contains some icon and label.
I want some additional text to be shown inplace when user touches the cell. The view with this text must be fullscreen width.
In other words I want to insert a view with text between collection rows. It's desirable that the view appears with animation.
How should I do that? The first ideas I've got are:
Divide CollectionView rows into sections and use section footer for this purpose. Make this footer of zero size and show it when needed.
Dynamically create full-width cell and insert it at the end of the row where selected item is located.
Both methods seems tricky to me. Maybe there is more straight forward way?
Any ideas? Thanks!

What should I do to set up the constraint on UICollectionView

I have a tableview which shows the news. And there's a UICollectionview inside each UITableview cell. Also there'll be some images inside collection view cell and the number of cells cannot be fixed because news may contain one image, two images or more.
The
UITableview cell looks like the following structure :
xxxxxxxxxxxxxxxxxx
name
news info
(UICollectionview img1 img2...)
UIButton and UILabel (such as like, dislike, comment..)
xxxxxxxxxxxxxxxxx
and I also set up the constraints. And I have to set up the width attribute for the UICollectionview. The main issue is that no matter how many images I may have for the news, the collection view will be always that wide and will block the click event for the tableview cell. So any ideas for that,
thx!
here is a suggest:
set the initial width constraint to 0, then changing it to actual width when bind data to cell.

Resources