Last active
November 15, 2018 13:00
-
-
Save gmoraleda/5bddf0f9d54c90a826ef2d625d5ee43f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getOffsetForDate(date: Date) -> CGFloat { | |
// dayViewHeight being the height of the view that containts the hour label and the line separator | |
let components = Calendar.current.dateComponents([.minute, .hour], from: date) | |
let hourOffset = CGFloat(components.hour ?? 0) * (dayViewHeight + Sizes.gridLineSeparation) | |
let minuteOffset = ceilToPixelsAccuracy(CGFloat(components.minute ?? 0) / 60 * (dayViewHeight + Sizes.gridLineSeparation)) | |
return hourOffset + minuteOffset + ceilToPixelsAccuracy(dayViewHeight / 2) | |
} | |
// Function to ceil according to the scaling factor | |
private func ceilToPixelsAccuracy(_ dots: CGFloat) -> CGFloat { | |
return ceil(dots * UIScreen.main.scale) / UIScreen.main.scale | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment