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 getMeColor() -> NSFetchRequest { | |
let sortTitle = NSSortDescriptor(key: "date", ascending: true) | |
self.fetchRequest = NSFetchRequest(entityName: "Fruits") | |
let context = managedObjectContext |
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
let entity = NSEntityDescription.entityForName("Fruits", inManagedObjectContext: context)! | |
fetchRequest.entity = entity | |
fetchRequest.sortDescriptors = [sortTitle] | |
ex.expressionResultType = .DecimalAttributeType | |
fetchRequest.propertiesToFetch = ["colors"] | |
fetchRequest.propertiesToGroupBy = ["colors"] | |
fetchRequest.resultType = .DictionaryResultType | |
let matchingObjects = try! context.executeFetchRequest(fetchRequest) as AnyObject | |
self.expenseCategory = matchingObjects |
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
var currentDate = Date() | |
var calendarArray: NSArray? |
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 arrayOfDates() -> NSArray { | |
let numberOfDays: Int = 14 | |
let startDate = Date() | |
let formatter: DateFormatter = DateFormatter() | |
formatter.dateFormat = "EEE d/M" | |
let calendar = Calendar.current | |
var offset = DateComponents() | |
var dates: [Any] = [formatter.string(from: startDate)] | |
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 collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | |
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellIdentifier, for: indexPath) as! CalendarViewCell | |
cell.dateLabel.text = self.calendarArray?[indexPath.row] as? String | |
return cell | |
} |
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
override var isSelected: Bool { | |
didSet { | |
if isSelected { | |
dateLabel!.textColor = UIColor.green | |
dateLabel.font = UIFont.boldSystemFont(ofSize: 14) | |
} else { | |
dateLabel!.textColor = UIColor.darkText | |
dateLabel.font = UIFont.systemFont(ofSize: 14) | |
} | |
} |
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
self.selectedDateLabel.text = self.calendarArray?[indexPath.row] as? String |
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
let centeredIndexPath = IndexPath.init(item: selectedDate, section: 0) | |
collectionView.scrollToItem(at: centeredIndexPath, at: .centeredHorizontally, animated: true) | |
if indexPath == centeredIndexPath { | |
collectionView.scrollToItem(at: indexPath, at: .centeredHorizontally, animated: true) | |
} |
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 scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { | |
if calendarCollectionView == scrollView { | |
setSelectedItemFromScrollView(scrollView) | |
} | |
} |
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 setSelectedItemFromScrollView(_ scrollView: UIScrollView) { | |
if calendarCollectionView == scrollView { | |
let center = CGPoint(x: scrollView.center.x + scrollView.contentOffset.x, y: scrollView.center.y + scrollView.contentOffset.y) | |
let index = calendarCollectionView.indexPathForItem(at: center) | |
if index != nil { | |
calendarCollectionView.scrollToItem(at: index!, at: .centeredHorizontally, animated: true) | |
self.calendarCollectionView.selectItem(at: index, animated: false, scrollPosition: []) | |
self.collectionView(self.calendarCollectionView, didSelectItemAt: index!) | |
self.selectedDate = (index?.row)! |
OlderNewer