Implementing scrollable horizontal menu - ios

I am new to iOS and trying to implement something exactly like the scrollable bar with the various sports show here.
I want the user to be able to scroll horizontally through the various options and be able to select one. It can be very simple like the one linked, as long as it is clear what is selected.
I'm not sure where exactly to start. Should I be using a CollectionView?

You are right - UICollectionView is the best option for you. Do set the collectionView's layout to UICollectionViewFlowLayout with horizontal direction.
Setup the UIViewController to be the collectionView's data source and delegate. The selection with tapping will be available immediately provided by default UICollectionView behaviour. The collectionView's delegate will allow you to intercept the event when collection is scrolled to new item so you would be able to determine the new selected item.

Related

How to create multiple next view for an iOS application

I just want to know what exactly should I use in storyboard UI so that I can create multiple views which can replace one view with the after a click of button:-
Replacing first view with second in this way
And not this way
You can use a CollectionView as the Header of a TableView if you want a UI shown in first image.
TableView will be having Chat options and the Collection View will be having images as you have in the given picture.
Quick Overview :- TableView only supports Vertical scrolling which is best in your use case.
Collection can support both vertical as well as horizontal scrolling. So basically what you can do is have a collection view of height as much as you want as a header of your tableview. So when the user scrolls through your tableview your scrollview will also move up just like we have in facebook and instagram stories.
Even if you have more images in collection view then your predefine height set the scroll mode as you prefer horizontal or Vertical so that user can have a look at everything you have in there.
Edit :- After editing your question this can be done for what you're looking :-
You need a Navigation Controller. Here's the Navigation Controller Push and Present of the answer which shows in detail how you can achieve that.
By doing Push you can achieve what you want (first image) and by doing present you'll achieve the second image result.

CollectionView Cell inside UITableView is not scrolling horizontally for Voice Over accessibility

In my app, I have a screen where I need to support voice over accessibility. The screen has a TableView and inside that a collectionView. When voice over is ON and when I try to single or three fingers swipe, the collectionView scroll is not working. The accessibility focus is not moving to the next cell. Voice over is working fine only for visible cells in collectionView.
I tried by disabling accessibility for collectionView Cell and UITableViewCell but still, it didn't work.
I want to make it work like in the AppStore, where we will have a similar kind of design.
I am attaching screenshots of my screen and some codes.
On your country cell on awakeFromNib function or your init function depends how you initialize the cell add the line self.contentView.isUserInteractionEnabled = false after super call.
The purpose of your screen isn't really clear to me but I can suggest an interesting way to use collection views with VoiceOver:
Define a UIAccessibilityElement to be inserted as a carousel element (element of your collection view).
Set its trait to .adjustable in order to select the different elements by swiping right or left.
Adapt the label and the value according to the selected cell.
Define the collection view [accessibilityElements].
It may be tedious 😓 but that's what Apple's engineers recommend ⟹ a complete and detailed example is introduced in a WWDC session, don't hesitate to take a look at it to perfectly implement your collection view for the VoiceOver users. 👍
what you need is just to say to tableview cell that your collection is accessible doing something like this:
accessibilityElements = [collectionView]

How do I implement the below view in iOS (Objective-C or Swift)?

Basically I'm trying to implement the feature which is attached as an image. I'm trying to create generic component. Where view can have list of items and minimum that could be shown will be two and there should be a button with 3 more options and click on should expand the view and auto adjust with the container using auto layout. Can any one help me giving brief idea how do I implement this? would be really help full.
Image and Component that I'm trying to implement is as below:
You will use UITableView with 2 UICustomCell one for default view like your image and another for expand view, use NSMutableArray to save flag value that decide to use the first cell or second cell, and in UIButton action reset this array and reload your UITableView.
I hope I help you.
1) If I right understand, the flexible solution it's creating UITableViewCell and UICollectionView as one of subviews (another - UIImageView). UICollectionView has two kinds of cells:
Cell with label - item.
Show more button.
Each time when you press Show more button just can reload UICollectionView without restrictions or insert new items.
But in this case you should manually calculate tableview's height. Implement sizeThatFits in UITableViewCell.
2) Also can add UIStackView and use it for your goal but UIStackView has bad performance.
Hope it helps you!

UICollectionView layout with custom layout

Is it possible to create a collection view with an item on the left and two items stacked to the right of it?
Whenever I specify the correct sizes to do this in the sizeForItemAtIndexPath delegate I can only get one item on the right side and the other is displayed in the next row underneath. I know I can do this with custom cells that contain more than one view (top and bottom) but I would like to know if its possible without that. It would be a lot less complex if I could do it without the custom double view cell. Im using a 'flow' layout with 'vertical' scroll direction (as per IB).
First image is what I hope to achieve and the second is what I am able to achieve currently.
You need to implement custom UICollectionViewFlowLayout subclass for this - Creating Custom Layouts

How to make cell doesn't scroll along with other cell?

I am making an app that use table View Controller and static cell.
I want to make first cell don't scrolling while other can. This is a picture of what i am talking about.(Sorry for my bad English)
For example as in this picture, I want to make 9gag tab stay when scroll. If you play instragram you will see that when you scrolling the name of user will stay until you scroll into another one. However I want it to stay not changing when it encounter second cell.
Any suggestion?
Using UITableViewController would not help here. You can use these steps to get what you want:
1. Create a UIViewController.
2. Add UITableView as its subview.
3. Add another UIView as UIViewController's view's subview.
4. Using auto layout constraints, you can put UIView above UITableView
This way, you will get a sticky view at the top.
Ok, not exactly sure what you're after but i'll take a stab.
Firstly, if you want the section to remain in place until a new section of items is present, you just need have a look at sections. This is an automatic feature. You may not see it occur until you have plenty of items in the sections.
UITableView With Multiple Sections
There's plenty of stuff about it & not too hard to implement.
My other guess of what you want:
If you want it to remain static regardless of anything, perhaps you could just create a view and place it above the table view. why does it need to be a part of it if it doesn't change?

Resources