I'm trying to create a custom calendar/ month view from scratch similar to this:
And with that I'm wondering what the correct approach would be. I'm calculating which weekday the first day of the month falls on (mon-sun), and the number of days in the month. This should be enough to determine how the calendar should look, but I'm stuck trying to figure out a way to lay this all out.
Is it best to have 37 buttons in a grid layout in the storyboard and iterate through them somehow, changing their label, or dynamically create these buttons on the fly? Is there any element/ framework in iOS I could make use of to make this process easier?
If going for the latter, how would you set up the constraints to make this scalable on different size classes and screen sizes?
Tim in first comment is right. The best way to build layout for custom calendar view such yours is UICollectionView. Also to make less mistakes you can use NSDate extensions like this one: https://github.com/erica/NSDate-Extensions
Related
I am trying to make a calendar like a google calendar in which each square has some text (events of the day).
For this, I think I must put a UITableView inside each UICollectionViewCell, but I am not accomplishing it. I don’t have a sample code because I don’t even know how to start solving this.
We don't need a UITableView, we can do it just by using UICollectionView.
But as you are new to this I suggest using a library JTAppleCalender.
With this library, you can create a calendar in iOS very easily and it is highly customizable.
List of features:
Range selection - select dates in a range. The design is entirely up
to you.
Boundary dates - limit the calendar date range
Week/month mode - show 1 row of weekdays. Or 2, 3 or 6
Custom cells - make your day-cells look however you want, with any
functionality you want
Custom calendar view - make your calendar look however you want, with
what ever functionality you want
First Day of week - pick anyday to be first day of the week
Horizontal or vertical mode
Ability to add month headers in varying sizes/styles of your liking
Ability to scroll to any month by simply using the date
Ability to design your calendar however you want. You want it, you
build it.
Github link: https://github.com/patchthecode/JTAppleCalendar
If you think that you don't want to use any library this answer may help you: Custom calender View
I want to create something like this(refer image)
as you can see in above image, here column represents date and row representing time. User can vertically scroll for time and horizontally for date. blank spaces will be clickable.
I have searched for similar kind of UI, but I don't know what to search. any thoughts to implement this custom UI will be a great help.
Thank you.
Here is the idea, if you want to implement a slightly simple design as displayed in your screenshot.
You can divide the complete UI in 3 small parts and design it,
To display "February 2017", you can addd a label.
TO display DATE, You can use CollectionView, which will have direction of Horizontal and set the content and create a logic by which you can display 31 for Month or week wise as per your need.
You want to display Time which scroll vertical, then to display that you can use Tableview in which time will be displayed.
Above is the just idea by which you can create a simple UI, in which
as per DATE selection, Time will be displayed in tableview.
What you are looking for is a week view which is similar like this component Calendar-UI. You can take it as a reference or modify in it as per your need.
You can customize the UICollectionView by subclassing UICollectionViewLayout to let UICollectionView behave the way you want.
Check this library, it may be helpful to you. Here is the github link.
How can I achieve week view of the calendar in my iOS app as shown below, ideally using Apple calendar components (if any) and also how can I retrieve the selected date.
I have tried using both FSCalender and CVCalender plugins, without much success, as each was missing one element or the other.
The answer is, you lay out a bunch of views and set their contents. Perhaps use a collection view for the horizontal days. Definitely use a table view for the times. There's nothing in the public SDK to do it all for you. You just put together a view hierarchy the normal way.
I am currently experimenting with a calendar framework I found online which possesses most of the functionality I need. However, I would really like to add a feature similar to the animation in the iOS Calendar where when a date is tapped, the view splits at that location and the selected week moves to the top of the calendar. Its an intuitive way to display info about the selected day. I just need some suggestions as to how this can be achieved since I'm not super familiar with collection views.
The calendar is a grid collection view with months as different sections from what I understand. Is it possible to just stick a supplementary view anywhere in a collection view dynamically? Or maybe I should look into adjusting insets at a specific location? I'm really not sure what direction to take and could use some suggestions.
Here is sort of what I want to do but with a table view.
How many cells to commence with in a UICollectionView for a Calendar? That is my understanding is:
UICollectionView is good in that it only instantiates cells it
needs to display, but then
You still have to add the cells to the collection view
So what is best practice if say your view would only show 10 cells, but you had unlimited cells (e.g. scrolling up and down dates in a calendar). Do you enter say 100 cells for 100 dates (say 50 either side of the starting date of interest) and then manually keep track of when you get to one of these edges and then add more? This would kind of be ashame the UICollectionView framework couldn't keep track of this itself no?
So overall questions therefore (sorry) are really:
How many cells (dates) should you be creating in the collectionview. Should it be limited therefore to say 100
Is there no support in UICollectionView to automate adding more cells in for you for a Calendar type situation where dates are endless if the user wants to keep scrolling forward or backward
Any what is impact on the caching strategy for UICollectionViewLayoutAttributes too?
There is a project on Github with a calendar based on UICollectionView
https://www.cocoacontrols.com/controls/rsdayflow
I have used this component in a production project.
You can easily change it's appearance since every day is a uicollectionviewcell.
This project is based on https://github.com/evadne/DayFlow
that can be a good base to create what you need.
If you want to build your own calendar it can help you to find response to your questions: the code is easy to understand, and the implementation is in my opinion quite neat
It depends on how much is visualized in one screen. If it is one month i would have one month before and one month later. If it is only a day, one day before, one day later. Then use this infinite scrolling trick. There are many examples outside. I didn't read through the following link, but the pictures visualize the idea nicely:
Building a Infinitely-Scrolling Gallery With a UICollectionView