zjfjack / JZCalendarWeekView

Calendar Week & Day View in iOS Swift
MIT License
460 stars 121 forks source link

I want add label row header for division row . #60

Open RanjeetStiga opened 5 years ago

RanjeetStiga commented 5 years ago

Hi I am using ZHourGridDivision.minutes_30 division and i want add row header label for 30 mins also . Like 19:00 , 19:30 etc thanks

zjfjack commented 5 years ago

this is not supported for now. If you want to implement this, you have to change the code in FlowLayout to achieve this.

RanjeetStiga commented 5 years ago

this is not supported for now. If you want to implement this, you have to change the code in FlowLayout to achieve this.

can you give any idea how and where need to change in FlowLayout ?

RanjeetStiga commented 5 years ago

this is not supported for now. If you want to implement this, you have to change the code in FlowLayout to achieve this.

can you give any idea how and where need to change in FlowLayout ?

Hi I am waiting from your response .

RanjeetStiga commented 5 years ago

this is not supported for now. If you want to implement this, you have to change the code in FlowLayout to achieve this.

can you give any idea how and where need to change in FlowLayout ?

Hi I am waiting from your response . Please reply asap.

zjfjack commented 5 years ago

Sorry, I missed this issue.

I will give you some suggestions later within a day.

zjfjack commented 5 years ago

This is not a quite easy way to do this, I cannot show you the full code but I will tell where you should change and the reason.

  1. From the beginning, the rowHeader layout all starts from JZWeekViewFlowLayout prepareHorizontalTileSectionLayoutForSections (line 236). For now, the total indexes are 24, you should change it to 48 instead. Also, if you want to keep the same hour height as current implementation, you should change the hourHeight to half of the current height. Furthermore, If you want to draw your own double (24 -> 48) horizontal grid lines rather than using 30-min Divisions, you should change the method layoutHorizontalGridLinesAttributes.

  2. After modifying the FlowLayout, you should try to change the current rowHeaderView to yours, which is defined in JZBaseWeekView viewForSupplementaryElementOfKind (line 466). Use your own dateFormat to update the time label text in JZRowHeader or your own class. Moreover, you have to amend the timeForRowHeader method in JZWeekViewFlowLayout. Previously it is 24, but for your case, minute components are introduced, you should calculate the correct Date here.

I think that's all for now, you can simply have a try. Let me know if you have more questions. The better way is to try and understand how it implements.

Thanks

RanjeetStiga commented 5 years ago

This is not a quite easy way to do this, I cannot show you the full code but I will tell where you should change and the reason.

  1. From the beginning, the rowHeader layout all starts from JZWeekViewFlowLayout prepareHorizontalTileSectionLayoutForSections (line 236). For now, the total indexes are 24, you should change it to 48 instead. Also, if you want to keep the same hour height as current implementation, you should change the hourHeight to half of the current height. Furthermore, If you want to draw your own double (24 -> 48) horizontal grid lines rather than using 30-min Divisions, you should change the method layoutHorizontalGridLinesAttributes.
  2. After modifying the FlowLayout, you should try to change the current rowHeaderView to yours, which is defined in JZBaseWeekView viewForSupplementaryElementOfKind (line 466). Use your own dateFormat to update the time label text in JZRowHeader or your own class. Moreover, you have to amend the timeForRowHeader method in JZWeekViewFlowLayout. Previously it is 24, but for your case, minute components are introduced, you should calculate the correct Date here.

I think that's all for now, you can simply have a try. Let me know if you have more questions. The better way is to try and understand how it implements.

Thanks

Can you explain in details of point 2 because i have changes same in code but it is not working.

Thanks,

zjfjack commented 5 years ago

In the method below


open func timeForRowHeader(at indexPath: IndexPath) -> Date {
    var components = daysForSection(indexPath.section)
    components.hour = indexPath.item
    return Calendar.current.date(from: components)!
}

The IndexPath range is from 0 - 24 currently, However, in your case, it should be 0-48, because you have more RowHeader SupplementaryView. You have to amend the Date calculation above to get the actual date for your each RowHeader. So the components are not just hour, it should like, for example, if the indexPath.item is 1, your components.hour = 0, components,minute = 30 (Currently is components.hour = 1). Do you get my idea? You have to give your own calculation date method for each RowHeader because your indexPath range is changed from 0-24 to 0-48.