Jtapplecalendar: Range with zero spacing between cells issue

Created on 21 Aug 2017  Â·  19Comments  Â·  Source: patchthecode/JTAppleCalendar

Hi

I want to achieve range selection with zero space between cells
But I have white spaces between cells so sometimes cell occurred to be less in width than others

I'm not altering cell size programmatically.

In storyboard I have image with trailing leading bottom and top constraints to cell
in calendar cell width and height is set up to 50
and cell size is 0 (like in example app)

Maybe I'm missing something when using library or maybe there is some issue for calculating cell width and height (I have tried different ratio for calendar width and height: square and rectangles )

Thanks in advance!

screen shot 2017-08-21 at 16 50 25

Most helpful comment

Yea, the spacing between cells problem is not a calendar issue. It is a UICollectionView issue.
If you try to do a range select on a regular UICollectionView, you will encounter this problem.

This problem occurs because of this:
we have 7 columns, and a fixed width. Therefore if the width is something like say 414. The cell's with will = 414 / 7 = 59.1428571429** recurring. That recurring number is what iscausing the thin line space.

To fix, follow these steps:

  1. Make sure that the yellow view is set with constraints so that its left and right edge is right up against its superview.
  2. Have your CalendarView CENTERED with constraints in the middle of the screen
  3. Set a width constraint on it.
  4. Create an IBOutlet for the width constraint. Make it = 414 or something.
  5. In your viewDidLoad, change the same width constraint to your new calculated number.
    Your new calculated number is as follows:
let width = self.view.frame.width
var cellSize = CGFloat(width / 7).rounded() // var cellSize = floor(CGFloat(width / 7))
var newWidth = cellSize * 7
  1. Set the width constraint outlet value to the newly calculated width.

All 19 comments

Yea, the spacing between cells problem is not a calendar issue. It is a UICollectionView issue.
If you try to do a range select on a regular UICollectionView, you will encounter this problem.

This problem occurs because of this:
we have 7 columns, and a fixed width. Therefore if the width is something like say 414. The cell's with will = 414 / 7 = 59.1428571429** recurring. That recurring number is what iscausing the thin line space.

To fix, follow these steps:

  1. Make sure that the yellow view is set with constraints so that its left and right edge is right up against its superview.
  2. Have your CalendarView CENTERED with constraints in the middle of the screen
  3. Set a width constraint on it.
  4. Create an IBOutlet for the width constraint. Make it = 414 or something.
  5. In your viewDidLoad, change the same width constraint to your new calculated number.
    Your new calculated number is as follows:
let width = self.view.frame.width
var cellSize = CGFloat(width / 7).rounded() // var cellSize = floor(CGFloat(width / 7))
var newWidth = cellSize * 7
  1. Set the width constraint outlet value to the newly calculated width.

Thank you very much for quick reply
I will recheck everything , try and let you know about results!

Update
unfortunately it did not help
I'll continue to search for solution. will post it here if I get something

Did not help? hmm
If it is possible you can provide a sample app with that selection screen. I can code the solution.

closing this issue.
If the problem is still existing for you, provide a small sample app. I'll re-opern this issue and code the fix.

simulator screen shot - iphone 5s - 2018-08-11 at 13 35 43

it still happened.

@meanreaksmey

what is the width of the calendarView when the app is run?

@patchthecode I set constraint left and right to superview.

@meanreaksmey yes.
therefore, what is the width of the calendaView when the app is run?

@patchthecode I used calendarView.cellSize = 50 and calendarView width depend on screen because I use constraint left right

Then this will not work.
You must know the width of your calendarView.
And the width when divided by 7 should not have a recurring point.

After I divided by 7 I used it for size cell right!.

On Sun, Aug 12, 2018 at 3:30 PM JTAppleCalendar notifications@github.com
wrote:

Then this will not work.
You must know the width of your calendarView.
And the width when divided by 7 should not have a recurring point.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/patchthecode/JTAppleCalendar/issues/538#issuecomment-412327426,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ASn9XFt4nDOHtTKhnk0tlRPOSO5TAzfDks5uP-eqgaJpZM4O9Yk2
.

@meanreaksmey
i do not understand what you mean.
Let me make this most simple.

Please run your app. And put this code in your viewDidLoad() in the controller you have your calendar.

        DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
            print(calendarView.frame.width)
        }

And let me know the width of your calendar view please?

@patchthecode
Hi, I have this issue as well, but only on iPhone X

On iPhoneX screenWidth if 375.
Then I set widthConstraint for Calendar:
calendarWidthConstraint.constant = 52 * 7

And in result I have this:

screen shot 2018-09-06 at 12 48 20 pm

@dbyst

screen shot 2018-08-29 at 8 25 05 am

@patchthecode
But in my example I have non-recurring decimal value

@dbyst When you pause your app on iphonex simulator, and you debug the view hierarchy, what is the width of the calendarView?
Tap on this to debug hierarchy
screen shot 2018-09-06 at 12 59 56 pm

I have an idea. Give us the width of the cells that are being automatically created for us instead of "0". That'd help.

@brandonaskea-mc but you are in control of the width of the cells via the width of the calendarView.width

Give us the width of the cells that are being automatically created for us instead of "0".

What exactly do i give you? A variable to change the width of the cell?

I solved this problem in cell swift file.
After awakeFromNib() method called in cell, I add this code.

let width = UIScreen.main.bounds.width  
let selectedViewSide = CGFloat(width/7).rounded() - 0.05
widthConstraint.constant = selectedViewSide
heightConstraint.constant = selectedViewSide

widthConstraint and heightConstraint are connected to selectedView width and height constraint.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

blinkmeoff picture blinkmeoff  Â·  3Comments

Kevinw14 picture Kevinw14  Â·  3Comments

prahaladm picture prahaladm  Â·  3Comments

leo150 picture leo150  Â·  3Comments

gotamafandy picture gotamafandy  Â·  3Comments