diff --git a/Example-Swift/FSCalendarSwiftExample.xcodeproj/project.pbxproj b/Example-Swift/FSCalendarSwiftExample.xcodeproj/project.pbxproj index c2474308..562399fc 100644 --- a/Example-Swift/FSCalendarSwiftExample.xcodeproj/project.pbxproj +++ b/Example-Swift/FSCalendarSwiftExample.xcodeproj/project.pbxproj @@ -37,6 +37,10 @@ F9CB48401E406A9200C92065 /* FSCalendarSwiftExampleUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9CB483F1E406A9200C92065 /* FSCalendarSwiftExampleUITests.swift */; }; F9CB48481E406B7300C92065 /* FSCalendarConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 30F4C9281E07C3AD00D2EC4D /* FSCalendarConstants.m */; }; F9DE053B1E3CCAE800902F7D /* CalendarConfigViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9DE053A1E3CCAE800902F7D /* CalendarConfigViewController.swift */; }; + FA1B318A2824AF86001860DC /* WorkTypeVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA1B31882824AF86001860DC /* WorkTypeVC.swift */; }; + FA1B318B2824AF86001860DC /* WorkTypeVC.xib in Resources */ = {isa = PBXBuildFile; fileRef = FA1B31892824AF86001860DC /* WorkTypeVC.xib */; }; + FA1B31932824B675001860DC /* WorkGroupVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA1B31912824B675001860DC /* WorkGroupVC.swift */; }; + FA1B31942824B675001860DC /* WorkGroupVC.xib in Resources */ = {isa = PBXBuildFile; fileRef = FA1B31922824B675001860DC /* WorkGroupVC.xib */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -102,6 +106,10 @@ F9CB48411E406A9200C92065 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; F9CB48471E406AB700C92065 /* Objc-Bridge-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Objc-Bridge-Header.h"; sourceTree = ""; }; F9DE053A1E3CCAE800902F7D /* CalendarConfigViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CalendarConfigViewController.swift; sourceTree = ""; }; + FA1B31882824AF86001860DC /* WorkTypeVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkTypeVC.swift; sourceTree = ""; }; + FA1B31892824AF86001860DC /* WorkTypeVC.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = WorkTypeVC.xib; sourceTree = ""; }; + FA1B31912824B675001860DC /* WorkGroupVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkGroupVC.swift; sourceTree = ""; }; + FA1B31922824B675001860DC /* WorkGroupVC.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = WorkGroupVC.xib; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -184,6 +192,7 @@ EE0954A91B97DDE0007F6964 /* FSCalendarSwiftExample */ = { isa = PBXGroup; children = ( + FA1B318C2824B1FE001860DC /* WorkType */, EE0954AC1B97DDE0007F6964 /* AppDelegate.swift */, 303478381DB520C8007BBD2E /* TableViewController.swift */, F95394791F26BF07005B83E5 /* LunarFormatter.swift */, @@ -221,6 +230,17 @@ path = FSCalendarSwiftExampleUITests; sourceTree = ""; }; + FA1B318C2824B1FE001860DC /* WorkType */ = { + isa = PBXGroup; + children = ( + FA1B31882824AF86001860DC /* WorkTypeVC.swift */, + FA1B31892824AF86001860DC /* WorkTypeVC.xib */, + FA1B31912824B675001860DC /* WorkGroupVC.swift */, + FA1B31922824B675001860DC /* WorkGroupVC.xib */, + ); + name = WorkType; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -271,7 +291,7 @@ TargetAttributes = { EE0954A61B97DDE0007F6964 = { CreatedOnToolsVersion = 6.4; - DevelopmentTeam = HZF422TY46; + DevelopmentTeam = 9689HPSFXL; LastSwiftMigration = 0900; }; F9CB483C1E406A9200C92065 = { @@ -309,6 +329,8 @@ buildActionMask = 2147483647; files = ( EE0954B21B97DDE0007F6964 /* Main.storyboard in Resources */, + FA1B31942824B675001860DC /* WorkGroupVC.xib in Resources */, + FA1B318B2824AF86001860DC /* WorkTypeVC.xib in Resources */, EE0954B71B97DDE0007F6964 /* LaunchScreen.xib in Resources */, EE0954B41B97DDE0007F6964 /* Images.xcassets in Resources */, ); @@ -329,6 +351,7 @@ buildActionMask = 2147483647; files = ( F9DE053B1E3CCAE800902F7D /* CalendarConfigViewController.swift in Sources */, + FA1B31932824B675001860DC /* WorkGroupVC.swift in Sources */, 30F4C9441E07C3AD00D2EC4D /* FSCalendarExtensions.m in Sources */, 30F4C93D1E07C3AD00D2EC4D /* FSCalendarCalculator.m in Sources */, 30F4C9411E07C3AD00D2EC4D /* FSCalendarConstants.m in Sources */, @@ -351,6 +374,7 @@ 30D458E91DB4E2DB00B163C7 /* LoadViewExampleViewController.swift in Sources */, 30031AAA1DCEA83200FC34FE /* DIYCalendarCell.swift in Sources */, EE0954AD1B97DDE0007F6964 /* AppDelegate.swift in Sources */, + FA1B318A2824AF86001860DC /* WorkTypeVC.swift in Sources */, EE0954AF1B97DDE0007F6964 /* InterfaceBuilderViewController.swift in Sources */, 30F4C9421E07C3AD00D2EC4D /* FSCalendarDelegationFactory.m in Sources */, ); @@ -498,9 +522,9 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = HZF422TY46; + DEVELOPMENT_TEAM = 9689HPSFXL; INFOPLIST_FILE = "$(SRCROOT)/FSCalendarSwiftExample/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.wenchaod.FSCalendarSwiftExample; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -515,9 +539,9 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - DEVELOPMENT_TEAM = HZF422TY46; + DEVELOPMENT_TEAM = 9689HPSFXL; INFOPLIST_FILE = "$(SRCROOT)/FSCalendarSwiftExample/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.wenchaod.FSCalendarSwiftExample; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/Example-Swift/FSCalendarSwiftExample/DIYExampleViewController.swift b/Example-Swift/FSCalendarSwiftExample/DIYExampleViewController.swift index 14b7305e..26984265 100644 --- a/Example-Swift/FSCalendarSwiftExample/DIYExampleViewController.swift +++ b/Example-Swift/FSCalendarSwiftExample/DIYExampleViewController.swift @@ -28,7 +28,7 @@ class DIYExampleViewController: UIViewController, FSCalendarDataSource, FSCalend view.backgroundColor = UIColor.groupTableViewBackground self.view = view - let height: CGFloat = UIDevice.current.model.hasPrefix("iPad") ? 400 : 300 + let height: CGFloat = UIDevice.current.model.hasPrefix("iPad") ? 600 : 500 let calendar = FSCalendar(frame: CGRect(x: 0, y: self.navigationController!.navigationBar.frame.maxY, width: view.frame.size.width, height: height)) calendar.dataSource = self calendar.delegate = self diff --git a/Example-Swift/FSCalendarSwiftExample/DelegateAppearanceViewController.swift b/Example-Swift/FSCalendarSwiftExample/DelegateAppearanceViewController.swift index b2c08aa0..035c91ba 100644 --- a/Example-Swift/FSCalendarSwiftExample/DelegateAppearanceViewController.swift +++ b/Example-Swift/FSCalendarSwiftExample/DelegateAppearanceViewController.swift @@ -42,7 +42,7 @@ class DelegateAppearanceViewController: UIViewController, FSCalendarDataSource, view.backgroundColor = UIColor.groupTableViewBackground self.view = view - let height: CGFloat = UIDevice.current.model.hasPrefix("iPad") ? 450 : 300 + let height: CGFloat = UIDevice.current.model.hasPrefix("iPad") ? 600 : 500 let calendar = FSCalendar(frame: CGRect(x:0, y:64, width:self.view.bounds.size.width, height:height)) calendar.dataSource = self calendar.delegate = self diff --git a/Example-Swift/FSCalendarSwiftExample/FSCalendarScopeViewController.swift b/Example-Swift/FSCalendarSwiftExample/FSCalendarScopeViewController.swift index dabd62f9..cbff37e3 100644 --- a/Example-Swift/FSCalendarSwiftExample/FSCalendarScopeViewController.swift +++ b/Example-Swift/FSCalendarSwiftExample/FSCalendarScopeViewController.swift @@ -34,7 +34,9 @@ class FSCalendarScopeExampleViewController: UIViewController, UITableViewDataSou super.viewDidLoad() if UIDevice.current.model.hasPrefix("iPad") { - self.calendarHeightConstraint.constant = 400 + self.calendarHeightConstraint.constant = 600 + } else { + self.calendarHeightConstraint.constant = 500 } self.calendar.select(Date()) diff --git a/Example-Swift/FSCalendarSwiftExample/InterfaceBuilderViewController.swift b/Example-Swift/FSCalendarSwiftExample/InterfaceBuilderViewController.swift index 94c25e79..397f3ad9 100644 --- a/Example-Swift/FSCalendarSwiftExample/InterfaceBuilderViewController.swift +++ b/Example-Swift/FSCalendarSwiftExample/InterfaceBuilderViewController.swift @@ -76,7 +76,9 @@ class InterfaceBuilderViewController: UIViewController, FSCalendarDataSource, FS super.viewDidLoad() if UIDevice.current.model.hasPrefix("iPad") { - self.calendarHeightConstraint.constant = 400 + self.calendarHeightConstraint.constant = 600 + } else { + self.calendarHeightConstraint.constant = 500 } self.calendar.appearance.caseOptions = [.headerUsesUpperCase,.weekdayUsesUpperCase] @@ -87,6 +89,7 @@ class InterfaceBuilderViewController: UIViewController, FSCalendarDataSource, FS // For UITest self.calendar.accessibilityIdentifier = "calendar" + self.calendar.locale = Locale(identifier: "ko") } diff --git a/Example-Swift/FSCalendarSwiftExample/LoadViewExampleViewController.swift b/Example-Swift/FSCalendarSwiftExample/LoadViewExampleViewController.swift index f440f359..9bab4ba7 100644 --- a/Example-Swift/FSCalendarSwiftExample/LoadViewExampleViewController.swift +++ b/Example-Swift/FSCalendarSwiftExample/LoadViewExampleViewController.swift @@ -8,24 +8,237 @@ import UIKit +let kIdWorkTypeGroup = "kIdWorkTypeGroup" + +let kWorkType6day = "kWorkType6day" +let kWorkType3day = "kWorkType3day" +let kWorkType21day = "kWorkType21day" +let kWorkType4day = "kWorkType4day" + +let workListIdOne = "workListIdOne" +let workListIdTwo = "workListIdTwo" +let workListIdThree = "workListIdThree" +let workListIdFour = "workListIdFour" + +class ManagerWorkType { + + static let listRepeat3Day = ["당","비", "휴"] + static let listRepeat6Day = ["주", "주", "야", "야", "비", "휴"] + static let listRepeat21Day = ["주", "주", "주", "주", "주", "비", "비", "야", "비", "야", "비", "야", "비", "당", "비", "야", "비", "야", "비", "당", "비"] + static let listRepeat4DayTime = ["주", "야", "비", "휴"] + + static let shared = ManagerWorkType() + var allWorkTypeModel: [WorkTypeModel] = [] + + @objc var workTypeId: String = "" + @objc var workGroupId: String = "" + + init(){} + + func getAllWorkType() -> [WorkTypeModel]{ + if self.allWorkTypeModel.count == 0 { + self.allWorkTypeModel = self.buildWorkTypeModel() + } + return self.allWorkTypeModel + } + + func buildWorkTypeModel() -> [WorkTypeModel]{ + + // repeat 3day - 당비휴 + let groupRepeat3Day1 = WorkGroupModel(id: workListIdOne, name: "1팀", start: 2, group: ManagerWorkType.listRepeat3Day) + let groupRepeat3Day2 = WorkGroupModel(id: workListIdTwo, name: "2팀", start: 3, group: ManagerWorkType.listRepeat3Day) + let groupRepeat3Day3 = WorkGroupModel(id: workListIdThree, name: "3팀", start: 4, group: ManagerWorkType.listRepeat3Day) + let groupRepeat3Day:[WorkGroupModel] = [groupRepeat3Day1, groupRepeat3Day2, groupRepeat3Day3] + + let calRepeat3Day = WorkTypeModel(id: kWorkType3day, name: "당비휴", groups: groupRepeat3Day) + + + // repeat 6day - 주주야야비휴 + + let groupRepeat6Day1 = WorkGroupModel(id: workListIdOne, name: "1팀", start: 5, group: ManagerWorkType.listRepeat6Day) + let groupRepeat6Day2 = WorkGroupModel(id: workListIdTwo, name: "2팀", start: 7, group: ManagerWorkType.listRepeat6Day) + let groupRepeat6Day3 = WorkGroupModel(id: workListIdThree, name: "3팀", start: 9, group: ManagerWorkType.listRepeat6Day) + let groupRepeat6Day:[WorkGroupModel] = [groupRepeat6Day1, groupRepeat6Day2, groupRepeat6Day3] + + let calRepeat6Day = WorkTypeModel(id: kWorkType6day, name: "주주야야비휴", groups: groupRepeat6Day) + + + // repeat 21day - 21주기 + let groupRepeat21Day1 = WorkGroupModel(id: workListIdOne, name: "1팀", start: 17, group: ManagerWorkType.listRepeat21Day) + let groupRepeat21Day2 = WorkGroupModel(id: workListIdTwo, name: "2팀", start: 3, group: ManagerWorkType.listRepeat21Day) + let groupRepeat21Day3 = WorkGroupModel(id: workListIdThree, name: "3팀", start: 10, group: ManagerWorkType.listRepeat21Day) + let groupRepeat21DayTime:[WorkGroupModel] = [groupRepeat21Day1, groupRepeat21Day2, groupRepeat21Day3] + + let calRepeat21Day = WorkTypeModel(id: kWorkType21day, name: "21주기", groups: groupRepeat21DayTime) + + + // repeat 4day - 4조2교대(주야비휴) + let groupRepeat4DayTime1 = WorkGroupModel(id: workListIdOne, name: "1팀", start: 1, group: ManagerWorkType.listRepeat4DayTime) + let groupRepeat4DayTime2 = WorkGroupModel(id: workListIdTwo, name: "2팀", start: 2, group: ManagerWorkType.listRepeat4DayTime) + let groupRepeat4DayTime3 = WorkGroupModel(id: workListIdThree, name: "3팀", start: 3, group: ManagerWorkType.listRepeat4DayTime) + let groupRepeat4DayTime4 = WorkGroupModel(id: workListIdFour, name: "4팀", start: 4, group: ManagerWorkType.listRepeat4DayTime) + let groupRepeat4DayTime:[WorkGroupModel] = [groupRepeat4DayTime1, groupRepeat4DayTime2, groupRepeat4DayTime3, groupRepeat4DayTime4] + + let calRepeat4Day = WorkTypeModel(id: kWorkType4day, name: "4조2교대(주야비휴)", groups: groupRepeat4DayTime) + + + return [calRepeat3Day, calRepeat6Day, calRepeat21Day, calRepeat4Day] + } + + func getCalendarCurrent(id:String) -> WorkTypeModel? { + return self.getAllWorkType().first { calenderShift in + return calenderShift.id == id + } + } + + static func saveConfigCalendarShift(worpTypeId: String, workGroupId: String){ + let value = "\(worpTypeId),\(workGroupId)" + let userDefault = UserDefaults.standard + userDefault.set(value, forKey: kIdWorkTypeGroup) + userDefault.synchronize() + } + + + static func getConfigCalendarShift() -> String? { + return UserDefaults.standard.string(forKey: kIdWorkTypeGroup) + } + + static func setupConfigCalendarShift() { + var haveConfig = false + if let workTypeGroupId = self.getConfigCalendarShift(), workTypeGroupId != "" { + let arr = workTypeGroupId.components(separatedBy: ",") + if arr.count == 2 { + ManagerWorkType.shared.workTypeId = arr[0] + ManagerWorkType.shared.workGroupId = arr[1] + haveConfig = true + } + } + + if !haveConfig { + let firstWorkType = ManagerWorkType.shared.getAllWorkType().first! // make sure have data + ManagerWorkType.shared.workTypeId = firstWorkType.id + ManagerWorkType.shared.workGroupId = firstWorkType.groups.first!.id // make sure have data + ManagerWorkType.saveConfigCalendarShift(worpTypeId: ManagerWorkType.shared.workTypeId, workGroupId: ManagerWorkType.shared.workGroupId) + } + } +} + +class WorkTypeModel { + let id: String! + let name: String! + let groups: [WorkGroupModel]! + + init(id: String, name: String, groups: [WorkGroupModel]) { + self.id = id + self.name = name + self.groups = groups + } + +} + + +class WorkGroupModel { + + let id: String! + let start: Int! + let end: Int! + let group: [String]! + let groupReverse: [String]! + let name: String! + + @objc init(id: String, name:String, start: Int, group: [String]) { + self.id = id + self.name = name + self.start = start + self.group = group + self.groupReverse = group.reversed() + self.end = start + group.count - 1 + } + + @objc func getDay(from date: Date) -> [AnyHashable : Any]? { + + let components = date.get(.day, .month, .year) + var title = "" + + if let day = components.day { + if day >= start { + let index = (day - start) % self.group.count + title = self.group[index] + } else { + let index = (end - day) % self.group.count + title = self.groupReverse[index] + } + } + + let result = self.getColorTitleBackground(title: title) + let titleColor = result.1 + let color = result.0 + + return ["title": title, "color": color, "titleColor": titleColor] + } + + func getColorTitleBackground(title: String) -> (String, String){ + + if title == "휴" { + return ("orange", "white") + } else if title == "비" { + return ("red", "white") + } + else if title == "당" { + return ("yellow", "black") + } + else if title == "주" { + return ("black", "white") + } + else if title == "야" { + return ("blue", "white") + } + return ("","") + } +} + + + +protocol CalendarShiftDelegate { + func reloadCalendar() +} + class LoadViewExampleViewController: UIViewController, FSCalendarDataSource, FSCalendarDelegate { private weak var calendar: FSCalendar! - + fileprivate let lunarFormatter = LunarFormatter() + fileprivate let gregorian: NSCalendar! = NSCalendar(calendarIdentifier:NSCalendar.Identifier.gregorian) + var workTypeId: String! + var workGroupId: String! + var workGroupModel: WorkGroupModel? + var workTypeModelCurrent:WorkTypeModel? override func loadView() { + ManagerWorkType.setupConfigCalendarShift() + + self.setupWorkTypeGroupid() let view = UIView(frame: UIScreen.main.bounds) view.backgroundColor = UIColor.groupTableViewBackground self.view = view - let height: CGFloat = UIDevice.current.model.hasPrefix("iPad") ? 400 : 300 + let height: CGFloat = UIDevice.current.model.hasPrefix("iPad") ? 600 : 500 let calendar = FSCalendar(frame: CGRect(x: 0, y: self.navigationController!.navigationBar.frame.maxY, width: self.view.bounds.width, height: height)) calendar.dataSource = self calendar.delegate = self calendar.backgroundColor = UIColor.white self.view.addSubview(calendar) + calendar.locale = Locale(identifier: "ko") self.calendar = calendar + let showWorkTypeBtn = UIBarButtonItem(title: "worktype", style: .done, target: self, action: #selector(showWorkType)) + self.navigationItem.rightBarButtonItem = showWorkTypeBtn + } + + @objc func showWorkType() { + let vc = WorkTypeVC.init(nibName: "WorkTypeVC", bundle: nil) + vc.delegate = self + vc.vc = self + self.navigationController?.pushViewController(vc, animated: true) } override func viewDidLoad() { @@ -33,10 +246,51 @@ class LoadViewExampleViewController: UIViewController, FSCalendarDataSource, FSC self.title = "FSCalendar" } + func setupWorkTypeGroupid(){ + + self.workTypeId = ManagerWorkType.shared.workTypeId + self.workGroupId = ManagerWorkType.shared.workGroupId + + self.workTypeModelCurrent = ManagerWorkType.shared.getCalendarCurrent(id: self.workTypeId) + if let _workTypeModel = self.workTypeModelCurrent { + if let _tempWorkGroupModel = _workTypeModel.groups.first(where: { workGroupModel in + workGroupModel.id == workGroupId + }) { + self.workGroupModel = _tempWorkGroupModel + } + } + } + func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) { if monthPosition == .previous || monthPosition == .next { calendar.setCurrentPage(date, animated: true) } } + + func calendar(_ calendar: FSCalendar, subToptitleFor date: Date) -> [AnyHashable : Any]? { + return self.workGroupModel?.getDay(from: date) + } +// func calendar(_ calendar: FSCalendar, numberOfEventsFor date: Date) -> Int { +// let day: Int! = self.gregorian.component(.day, from: date) +// return day % 5 == 0 ? day/5 : 0; +// } +} + +extension LoadViewExampleViewController: CalendarShiftDelegate { + func reloadCalendar() { + self.setupWorkTypeGroupid() + self.calendar.reloadData() + } +} + + +extension Date { + func get(_ components: Calendar.Component..., calendar: Calendar = Calendar.current) -> DateComponents { + return calendar.dateComponents(Set(components), from: self) + } + + func get(_ component: Calendar.Component, calendar: Calendar = Calendar.current) -> Int { + return calendar.component(component, from: self) + } } diff --git a/Example-Swift/FSCalendarSwiftExample/LunarFormatter.swift b/Example-Swift/FSCalendarSwiftExample/LunarFormatter.swift index e7e6751d..f2c578a3 100644 --- a/Example-Swift/FSCalendarSwiftExample/LunarFormatter.swift +++ b/Example-Swift/FSCalendarSwiftExample/LunarFormatter.swift @@ -14,7 +14,7 @@ open class LunarFormatter: NSObject { fileprivate let formatter = DateFormatter() fileprivate let lunarDays = ["初二","初三","初四","初五","初六","初七","初八","初九","初十","十一","十二","十三","十四","十五","十六","十七","十八","十九","二十","二一","二二","二三","二四","二五","二六","二七","二八","二九","三十"] fileprivate let lunarMonths = ["正月","二月","三月","四月","五月","六月","七月","八月","九月","十月","冬月","腊月"] - + fileprivate let lunarKoreanday = ["비","휴","주","야"] override init() { self.formatter.calendar = self.chineseCalendar @@ -39,4 +39,55 @@ open class LunarFormatter: NSObject { return "闰" + self.lunarMonths[month-1] } + open func stringKorean(from toDate: Date) -> [AnyHashable : Any] { + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "yyyy-MM-dd" + let startDate = dateFormatter.date(from: "1970-01-01")! +// let startDate = dateFormatter.date(from: "2022-05-03")! + let day = startDate.fullDistance(from: toDate, resultIn: .day)! + let split = day % 4 + print("-------- \(String(describing: split))") + var title = "" + var color = "" + var titleColor = "" + if split == 1 { + title = lunarKoreanday[0] + color = "orange" + titleColor = "brown" + } else if split == 2 { + title = lunarKoreanday[1] + color = "red" + titleColor = "white" + + } else if split == 3 { + title = lunarKoreanday[2] + color = "yellow" + titleColor = "black" + } else if split == 0 { + title = lunarKoreanday[3] + color = "black" + titleColor = "white" + + } + + return ["title": title, "color": color, "titleColor": titleColor] + } +} + +extension Date { + + func fullDistance(from date: Date, resultIn component: Calendar.Component, calendar: Calendar = .current) -> Int? { + calendar.dateComponents([component], from: self, to: date).value(for: component) + } + + func distance(from date: Date, only component: Calendar.Component, calendar: Calendar = .current) -> Int { + let days1 = calendar.component(component, from: self) + let days2 = calendar.component(component, from: date) + return days1 - days2 + } + + func hasSame(_ component: Calendar.Component, as date: Date) -> Bool { + distance(from: date, only: component) == 0 + } } + diff --git a/Example-Swift/FSCalendarSwiftExample/WorkGroupVC.swift b/Example-Swift/FSCalendarSwiftExample/WorkGroupVC.swift new file mode 100644 index 00000000..1b764b00 --- /dev/null +++ b/Example-Swift/FSCalendarSwiftExample/WorkGroupVC.swift @@ -0,0 +1,91 @@ +// +// WorkGroupVC.swift +// FSCalendarSwiftExample +// +// Created by Trinh Huu Tien on 5/6/22. +// Copyright © 2022 wenchao. All rights reserved. +// + +import UIKit + + + +class WorkGroupVC: UIViewController { + + @IBOutlet weak var tableView: UITableView! + @IBOutlet weak var btnApply: UIButton! + weak var vc: UIViewController? + var workGroups: [WorkGroupModel]! + var workTypeId: String! + var workGroupId: String = "" + + var delegate: CalendarShiftDelegate? + override func viewDidLoad() { + super.viewDidLoad() + self.btnApply.isEnabled = false + if ManagerWorkType.shared.workTypeId == self.workTypeId { + self.workGroupId = ManagerWorkType.shared.workGroupId + } + + self.tableView.dataSource = self + self.tableView.delegate = self + + self.btnApply.layer.cornerRadius = self.btnApply.frame.height / 2 + self.btnApply.layer.masksToBounds = true + + } + + @IBAction func applyClick(_ button: UIButton){ + if(self.workTypeId != ManagerWorkType.shared.workGroupId) { + ManagerWorkType.saveConfigCalendarShift(worpTypeId: self.workTypeId, workGroupId: self.workGroupId) + ManagerWorkType.setupConfigCalendarShift() + self.delegate?.reloadCalendar() + } + if let _vc = self.vc { + self.navigationController?.popToViewController(_vc, animated: true) + } else { + self.navigationController?.popViewController(animated: true) + } + + + } + + func isSelecteWorkType(workGroupId: String) -> Bool{ + return self.workGroupId == workGroupId + } + + +} + +extension WorkGroupVC: UITableViewDataSource { + + + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return self.workGroups.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let model = self.workGroups[indexPath.row] + let cell = UITableViewCell(style: .default, reuseIdentifier: "Cell") + cell.textLabel?.text = model.name + cell.separatorInset = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10) + cell.accessoryType = self.isSelecteWorkType(workGroupId: model.id) ? UITableViewCellAccessoryType.checkmark : UITableViewCellAccessoryType.none + cell.selectionStyle = UITableViewCellSelectionStyle.none + return cell + } + +} + +extension WorkGroupVC: UITableViewDelegate { + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + self.workGroupId = self.workGroups[indexPath.row].id + self.btnApply.isEnabled = !(self.workGroupId == ManagerWorkType.shared.workGroupId && self.workTypeId == ManagerWorkType.shared.workTypeId) +// var indexPaths = [indexPath] +// if let _indexPathDeselect = self.tableView.indexPat { +// indexPaths.append(_indexPathDeselect) +// } + self.tableView.reloadData() + } + + +} diff --git a/Example-Swift/FSCalendarSwiftExample/WorkGroupVC.xib b/Example-Swift/FSCalendarSwiftExample/WorkGroupVC.xib new file mode 100644 index 00000000..c54dda83 --- /dev/null +++ b/Example-Swift/FSCalendarSwiftExample/WorkGroupVC.xib @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Example-Swift/FSCalendarSwiftExample/WorkTypeVC.swift b/Example-Swift/FSCalendarSwiftExample/WorkTypeVC.swift new file mode 100644 index 00000000..3fba496a --- /dev/null +++ b/Example-Swift/FSCalendarSwiftExample/WorkTypeVC.swift @@ -0,0 +1,61 @@ +// +// WorkTypeVC.swift +// FSCalendarSwiftExample +// +// Created by Trinh Huu Tien on 5/6/22. +// Copyright © 2022 wenchao. All rights reserved. +// + +import UIKit + +class WorkTypeVC: UIViewController { + + @IBOutlet weak var tableView: UITableView! + var delegate: CalendarShiftDelegate? + weak var vc: UIViewController? + override func viewDidLoad() { + super.viewDidLoad() + + self.tableView.dataSource = self + self.tableView.delegate = self + + + + } + +} + +extension WorkTypeVC: UITableViewDataSource { + + + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return ManagerWorkType.shared.getAllWorkType().count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let model = ManagerWorkType.shared.getAllWorkType()[indexPath.row] + let cell = UITableViewCell(style: .default, reuseIdentifier: "Cell") + cell.textLabel?.text = model.name + cell.separatorInset = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10) + cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator + cell.selectionStyle = UITableViewCellSelectionStyle.none + return cell + } + +} + +extension WorkTypeVC: UITableViewDelegate { + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let vc = WorkGroupVC(nibName: "WorkGroupVC", bundle: nil) + let model = ManagerWorkType.shared.getAllWorkType()[indexPath.row] + vc.workGroups = model.groups + vc.workTypeId = model.id + vc.delegate = self.delegate + vc.vc = self.vc + + vc.title = model.name + self.navigationController?.pushViewController(vc, animated: true) + + } + +} diff --git a/Example-Swift/FSCalendarSwiftExample/WorkTypeVC.xib b/Example-Swift/FSCalendarSwiftExample/WorkTypeVC.xib new file mode 100644 index 00000000..d539a846 --- /dev/null +++ b/Example-Swift/FSCalendarSwiftExample/WorkTypeVC.xib @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Example-Swift/FSCalendarSwiftExampleUITests/FSCalendarSwiftExampleUITests.swift b/Example-Swift/FSCalendarSwiftExampleUITests/FSCalendarSwiftExampleUITests.swift index 6b4b1ec7..4deeea34 100644 --- a/Example-Swift/FSCalendarSwiftExampleUITests/FSCalendarSwiftExampleUITests.swift +++ b/Example-Swift/FSCalendarSwiftExampleUITests/FSCalendarSwiftExampleUITests.swift @@ -49,7 +49,7 @@ class FSCalendarSwiftExampleUITests: XCTestCase { application.tables.element(boundBy: 0).staticTexts["Delegate Appearance"].tap() let calendar: XCUIElement = application.otherElements["calendar"] - let calendarHeight: CGFloat = UIDevice.current.model.hasPrefix("iPad") ? 400 : 300 + let calendarHeight: CGFloat = UIDevice.current.model.hasPrefix("iPad") ? 600 : 500 let cellStart: CGFloat = (FSCalendarStandardHeaderHeight+FSCalendarStandardWeekdayHeight)/calendarHeight let rowHeight: CGFloat = (1.0-cellStart)/6.0 let columnWidth: CGFloat = 1.0/7 @@ -109,7 +109,7 @@ class FSCalendarSwiftExampleUITests: XCTestCase { let application = XCUIApplication() application.tables.element(boundBy: 0).staticTexts["Interface Builder"].tap() let calendar = application.otherElements["calendar"] - let calendarHeight: CGFloat = UIDevice.current.model.hasPrefix("iPad") ? 400 : 300 + let calendarHeight: CGFloat = UIDevice.current.model.hasPrefix("iPad") ? 600 : 500 let cellStart: CGFloat = (FSCalendarStandardHeaderHeight+FSCalendarStandardWeekdayHeight)/calendarHeight let rowHeight: CGFloat = (1.0-cellStart)/6.0 let columnWidth: CGFloat = 1.0/7 diff --git a/FSCalendar/FSCalendar.h b/FSCalendar/FSCalendar.h index 0379d097..6c02728c 100644 --- a/FSCalendar/FSCalendar.h +++ b/FSCalendar/FSCalendar.h @@ -63,6 +63,8 @@ NS_ASSUME_NONNULL_BEGIN @optional + +- (nullable NSDictionary *)calendar:(FSCalendar *)calendar subToptitleForDate:(NSDate *)date; /** * Asks the dataSource for a title for the specific date as a replacement of the day text */ diff --git a/FSCalendar/FSCalendar.m b/FSCalendar/FSCalendar.m index baa8bd64..cd1ddc30 100644 --- a/FSCalendar/FSCalendar.m +++ b/FSCalendar/FSCalendar.m @@ -1375,6 +1375,22 @@ - (void)invalidateAppearanceForCell:(FSCalendarCell *)cell forDate:(NSDate *)dat } +- (FSCalendarCellDay)getDayType:(NSDate *) date{ + NSDateComponents *component = [[NSCalendar currentCalendar] components:NSCalendarUnitWeekday fromDate:date]; + + switch ([component weekday]) { + case 1: + return FSCalendarSunday; + break; + case 7: + return FSCalendarSaturday; + break; + default: + break; + } + return FSCalendarNormalDay; +} + - (void)reloadDataForCell:(FSCalendarCell *)cell atIndexPath:(NSIndexPath *)indexPath { cell.calendar = self; @@ -1383,10 +1399,13 @@ - (void)reloadDataForCell:(FSCalendarCell *)cell atIndexPath:(NSIndexPath *)inde cell.numberOfEvents = [self.dataSourceProxy calendar:self numberOfEventsForDate:date]; cell.titleLabel.text = [self.dataSourceProxy calendar:self titleForDate:date] ?: @([self.gregorian component:NSCalendarUnitDay fromDate:date]).stringValue; cell.subtitle = [self.dataSourceProxy calendar:self subtitleForDate:date]; + cell.topTitle = [self.dataSourceProxy calendar:self subToptitleForDate:date]; cell.selected = [_selectedDates containsObject:date]; cell.dateIsToday = self.today?[self.gregorian isDate:date inSameDayAsDate:self.today]:NO; cell.weekend = [self.gregorian isDateInWeekend:date]; cell.monthPosition = [self.calculator monthPositionForIndexPath:indexPath]; + cell.dayType = [self getDayType:date]; + switch (self.transitionCoordinator.representingScope) { case FSCalendarScopeMonth: { cell.placeholder = (cell.monthPosition == FSCalendarMonthPositionPrevious || cell.monthPosition == FSCalendarMonthPositionNext) || ![self isDateInRange:date]; diff --git a/FSCalendar/FSCalendarAppearance.h b/FSCalendar/FSCalendarAppearance.h index b0af6af7..3d6d8b2d 100644 --- a/FSCalendar/FSCalendarAppearance.h +++ b/FSCalendar/FSCalendarAppearance.h @@ -44,6 +44,9 @@ typedef NS_OPTIONS(NSUInteger, FSCalendarCaseOptions) { */ @interface FSCalendarAppearance : NSObject + +@property (strong, nonatomic) UIFont *headerCellFont; + /** * The font of the day text. */ @@ -93,6 +96,9 @@ typedef NS_OPTIONS(NSUInteger, FSCalendarCaseOptions) { * The color of event dots. */ @property (strong, nonatomic) UIColor *eventDefaultColor; +//tienth +@property (strong, nonatomic) UIColor *sundayColor; +@property (strong, nonatomic) UIColor *saturdayColor; /** * The color of event dots. diff --git a/FSCalendar/FSCalendarAppearance.m b/FSCalendar/FSCalendarAppearance.m index b7c0d046..a6a12ac7 100644 --- a/FSCalendar/FSCalendarAppearance.m +++ b/FSCalendar/FSCalendarAppearance.m @@ -31,17 +31,21 @@ - (instancetype)init if (self) { _titleFont = [UIFont systemFontOfSize:FSCalendarStandardTitleTextSize]; +// _titleFont = [UIFont systemFontOfSize:FSCalendarStandardTitleTextSize weight:UIFontWeightBold]; _subtitleFont = [UIFont systemFontOfSize:FSCalendarStandardSubtitleTextSize]; - _weekdayFont = [UIFont systemFontOfSize:FSCalendarStandardWeekdayTextSize]; + _weekdayFont = [UIFont systemFontOfSize:FSCalendarStandardWeekdayTextSize weight:UIFontWeightBold]; +// _weekdayFont = [UIFont systemFontOfSize:FSCalendarStandardWeekdayTextSize]; _headerTitleFont = [UIFont systemFontOfSize:FSCalendarStandardHeaderTextSize]; - + _headerCellFont = [UIFont systemFontOfSize:FSCalendarStandardSubtitleTextSize]; + _sundayColor = FSCalendarSundayTextColor; + _saturdayColor = FSCalendarSaturdayTextColor; _headerTitleColor = FSCalendarStandardTitleTextColor; _headerSeparatorColor = FSCalendarStandardLineColor; _headerDateFormat = @"MMMM yyyy"; _headerMinimumDissolvedAlpha = 0.2; _headerTitleOffset = CGPointZero; _headerTitleAlignment = NSTextAlignmentCenter; - _weekdayTextColor = FSCalendarStandardTitleTextColor; + _weekdayTextColor = FSCalendarWeekendTextColor; _caseOptions = FSCalendarCaseOptionsHeaderUsesDefaultCase|FSCalendarCaseOptionsWeekdayUsesDefaultCase; _backgroundColors = [NSMutableDictionary dictionaryWithCapacity:5]; @@ -65,6 +69,8 @@ - (instancetype)init _subtitleColors[@(FSCalendarCellStatePlaceholder)] = [UIColor lightGrayColor]; _subtitleColors[@(FSCalendarCellStateToday)] = [UIColor whiteColor]; + + _borderColors[@(FSCalendarCellStateSelected)] = [UIColor clearColor]; _borderColors[@(FSCalendarCellStateNormal)] = [UIColor clearColor]; diff --git a/FSCalendar/FSCalendarCell.h b/FSCalendar/FSCalendarCell.h index f252b3b2..12655873 100644 --- a/FSCalendar/FSCalendarCell.h +++ b/FSCalendar/FSCalendarCell.h @@ -11,11 +11,19 @@ @class FSCalendar, FSCalendarAppearance, FSCalendarEventIndicator; typedef NS_ENUM(NSUInteger, FSCalendarMonthPosition); +typedef NS_ENUM(NSUInteger, FSCalendarCellDay) { + FSCalendarNormalDay, + FSCalendarSunday, + FSCalendarSaturday, +}; @interface FSCalendarCell : UICollectionViewCell #pragma mark - Public properties + +@property (weak, nonatomic) UILabel *topTitleLabel; + /** The day text label of the cell */ @@ -54,6 +62,7 @@ typedef NS_ENUM(NSUInteger, FSCalendarMonthPosition); @property (weak, nonatomic) FSCalendar *calendar; @property (weak, nonatomic) FSCalendarAppearance *appearance; +@property (strong, nonatomic) NSDictionary *topTitle; @property (strong, nonatomic) NSString *subtitle; @property (strong, nonatomic) UIImage *image; @property (assign, nonatomic) FSCalendarMonthPosition monthPosition; @@ -61,6 +70,7 @@ typedef NS_ENUM(NSUInteger, FSCalendarMonthPosition); @property (assign, nonatomic) NSInteger numberOfEvents; @property (assign, nonatomic) BOOL dateIsToday; @property (assign, nonatomic) BOOL weekend; +@property (assign, nonatomic) FSCalendarCellDay dayType; @property (strong, nonatomic) UIColor *preferredFillDefaultColor; @property (strong, nonatomic) UIColor *preferredFillSelectionColor; @@ -78,6 +88,7 @@ typedef NS_ENUM(NSUInteger, FSCalendarMonthPosition); @property (strong, nonatomic) NSArray *preferredEventDefaultColors; @property (strong, nonatomic) NSArray *preferredEventSelectionColors; @property (assign, nonatomic) CGFloat preferredBorderRadius; +@property (assign, nonatomic) BOOL isCustom; // Add subviews to self.contentView and set up constraints - (instancetype)initWithFrame:(CGRect)frame NS_REQUIRES_SUPER; diff --git a/FSCalendar/FSCalendarCell.m b/FSCalendar/FSCalendarCell.m index 9c930a64..24c8ac4d 100644 --- a/FSCalendar/FSCalendarCell.m +++ b/FSCalendar/FSCalendarCell.m @@ -46,12 +46,20 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder } - (void)commonInit -{ +{ + UILabel *topLabel; UILabel *label; CAShapeLayer *shapeLayer; UIImageView *imageView; FSCalendarEventIndicator *eventIndicator; + + topLabel = [[UILabel alloc] initWithFrame:CGRectZero]; + topLabel.textAlignment = NSTextAlignmentCenter; + topLabel.textColor = [UIColor blackColor]; + [self.contentView addSubview:topLabel]; + self.topTitleLabel = topLabel; + label = [[UILabel alloc] initWithFrame:CGRectZero]; label.textAlignment = NSTextAlignmentCenter; label.textColor = [UIColor blackColor]; @@ -88,9 +96,68 @@ - (void)commonInit } +- (UIColor *)getColorTopBackgroundTitle:(NSString *)colorStr { + UIColor *color = UIColor.blackColor; + if([colorStr isEqualToString:@"black"]) { + color = UIColor.blackColor; + } else if([colorStr isEqualToString:@"orange"]) { + color = UIColor.orangeColor; + } else if([colorStr isEqualToString:@"red"]) { + color = UIColor.redColor; + } else if([colorStr isEqualToString:@"yellow"]) { + color = UIColor.yellowColor; + } else if([colorStr isEqualToString:@"blue"]) { + color = UIColor.blueColor; + } + return self.placeholder ? [color colorWithAlphaComponent:0.5] : color; +} + +- (UIColor *)getColorTopTitleColor:(NSString *)colorStr { + UIColor *color = UIColor.whiteColor; + if([colorStr isEqualToString:@"brown"]) { + color = UIColor.brownColor; + } else if([colorStr isEqualToString:@"white"]) { + color = UIColor.whiteColor; + } else if([colorStr isEqualToString:@"black"]) { + color = UIColor.blackColor; + } + return self.placeholder ? [color colorWithAlphaComponent:0.5] : color; +} + - (void)layoutSubviews { [super layoutSubviews]; + + + if(_topTitle){ + _topTitleLabel.text = _topTitle[@"title"]; + _topTitleLabel.textColor = [self getColorTopTitleColor:_topTitle[@"titleColor"]]; + _topTitleLabel.backgroundColor = [self getColorTopBackgroundTitle:_topTitle[@"color"]]; + if (_topTitleLabel.hidden) { + _topTitleLabel.hidden = NO; + } + } else { + if (!_topTitleLabel.hidden) { + _topTitleLabel.hidden = YES; + } + } + + + if(_topTitle){ + _topTitleLabel.frame = CGRectMake( + 0, + 0, + self.contentView.frame.size.width * 0.4, + self.calendar.appearance.headerCellFont.lineHeight + ); + + } else { + _topTitleLabel.frame = CGRectZero; + } + + self.contentView.layer.borderColor = [[UIColor colorWithRed:51/255.0f green:51/255.0f blue:51/255.0f alpha:1] CGColor]; + self.contentView.layer.borderWidth = 0.5f; + if (_subtitle) { _subtitleLabel.text = _subtitle; if (_subtitleLabel.hidden) { @@ -122,19 +189,19 @@ - (void)layoutSubviews } else { _titleLabel.frame = CGRectMake( self.preferredTitleOffset.x, - self.preferredTitleOffset.y, + _topTitleLabel.font.pointSize + self.preferredTitleOffset.y, self.contentView.fs_width, - floor(self.contentView.fs_height*5.0/6.0) + floor(self.contentView.fs_height*5.0/6.0) - _topTitleLabel.font.pointSize ); } _imageView.frame = CGRectMake(self.preferredImageOffset.x, self.preferredImageOffset.y, self.contentView.fs_width, self.contentView.fs_height); - CGFloat titleHeight = self.bounds.size.height*5.0/6.0; - CGFloat diameter = MIN(self.bounds.size.height*5.0/6.0,self.bounds.size.width); + CGFloat titleHeight = self.titleLabel.frame.size.height*6.0/6.0; + CGFloat diameter = MIN(titleHeight,self.titleLabel.frame.size.width); diameter = diameter > FSCalendarStandardCellDiameter ? (diameter - (diameter-FSCalendarStandardCellDiameter)*0.5) : diameter; _shapeLayer.frame = CGRectMake((self.bounds.size.width-diameter)/2, - (titleHeight-diameter)/2, + self.titleLabel.frame.origin.y + (titleHeight-diameter)/2, diameter, diameter); @@ -187,10 +254,19 @@ - (void)performSelecting } +- (BOOL)isWeekend:(NSDate *)date{ + return [[NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian] isDateInWeekend:date]; +} + #pragma mark - Private - (void)configureAppearance { + + if(_topTitle){ + _topTitleLabel.font = self.calendar.appearance.headerCellFont; + } + UIColor *textColor = self.colorForTitleLabel; if (![textColor isEqual:_titleLabel.textColor]) { _titleLabel.textColor = textColor; @@ -199,6 +275,15 @@ - (void)configureAppearance if (![titleFont isEqual:_titleLabel.font]) { _titleLabel.font = titleFont; } + + if(self.dayType == FSCalendarSunday){ + _titleLabel.font = self.calendar.appearance.weekdayFont; + _titleLabel.textColor = [self colorForWeekend:self.dayType]; + } else if(self.dayType == FSCalendarSaturday){ + _titleLabel.font = self.calendar.appearance.weekdayFont; + _titleLabel.textColor = [self colorForWeekend:self.dayType]; + } + if (_subtitle) { textColor = self.colorForSubtitleLabel; if (![textColor isEqual:_subtitleLabel.textColor]) { @@ -231,7 +316,7 @@ - (void)configureAppearance } CGPathRef path = [UIBezierPath bezierPathWithRoundedRect:_shapeLayer.bounds - cornerRadius:CGRectGetWidth(_shapeLayer.bounds)*0.5*self.borderRadius].CGPath; + cornerRadius:CGRectGetWidth(_shapeLayer.bounds)*0.5*self.borderRadius*0.5].CGPath; if (!CGPathEqualToPath(_shapeLayer.path, path)) { _shapeLayer.path = path; } @@ -282,6 +367,20 @@ - (UIColor *)colorForCellFill return self.preferredFillDefaultColor ?: [self colorForCurrentStateInDictionary:_appearance.backgroundColors]; } +- (UIColor *)colorForWeekend:(FSCalendarCellDay)dayType +{ + if (self.selected) { + return UIColor.whiteColor; + } + + if(dayType == FSCalendarSunday){ + return self.placeholder ? [self.calendar.appearance.sundayColor colorWithAlphaComponent:0.5] : self.calendar.appearance.sundayColor; + } else { + return self.placeholder ? [self.calendar.appearance.saturdayColor colorWithAlphaComponent:0.5] : self.calendar.appearance.saturdayColor; + } + +} + - (UIColor *)colorForTitleLabel { if (self.selected) { diff --git a/FSCalendar/FSCalendarConstants.h b/FSCalendar/FSCalendarConstants.h index 5d287e9e..19188627 100644 --- a/FSCalendar/FSCalendarConstants.h +++ b/FSCalendar/FSCalendarConstants.h @@ -48,7 +48,10 @@ CG_EXTERN CGSize const CGSizeAutomatic; #define FSCalendarStandardTodayColor FSColorRGBA(198,51,42 ,1.0) #define FSCalendarStandardTitleTextColor FSColorRGBA(14,69,221 ,1.0) #define FSCalendarStandardEventDotColor FSColorRGBA(31,119,219,0.75) - +#define FSCalendarWeekendTextColor FSColorRGBA(173,26,38 ,1.0) +#define FSCalendarSaturdayTextColor FSColorRGBA(25,42,194,1.0) +#define FSCalendarSundayTextColor FSColorRGBA(173,26,38 ,1.0) +#define FSCalendarWeekendTextDisableColor FSColorRGBA(158,79,86 ,0.7) #define FSCalendarStandardLineColor [[UIColor lightGrayColor] colorWithAlphaComponent:0.30] #define FSCalendarStandardSeparatorColor [[UIColor lightGrayColor] colorWithAlphaComponent:0.60] diff --git a/FSCalendar/FSCalendarWeekdayView.m b/FSCalendar/FSCalendarWeekdayView.m index 95028d77..444c4300 100644 --- a/FSCalendar/FSCalendarWeekdayView.m +++ b/FSCalendar/FSCalendarWeekdayView.m @@ -10,6 +10,7 @@ #import "FSCalendar.h" #import "FSCalendarDynamicHeader.h" #import "FSCalendarExtensions.h" +#import "FSCalendarCell.h" @interface FSCalendarWeekdayView() @@ -106,10 +107,31 @@ - (void)configureAppearance NSInteger index = (i + self.calendar.firstWeekday-1) % 7; UILabel *label = [self.weekdayPointers pointerAtIndex:i]; label.font = self.calendar.appearance.weekdayFont; - label.textColor = self.calendar.appearance.weekdayTextColor; + label.textColor = [self getColor:weekdaySymbols[index]]; label.text = useDefaultWeekdayCase ? weekdaySymbols[index] : [weekdaySymbols[index] uppercaseString]; } } +- (UIColor *)getColor:(NSString *)day { + FSCalendarCellDay dayType = [self getDayType:day]; + if(dayType == FSCalendarSunday) { + return self.calendar.appearance.sundayColor; + } else if(dayType == FSCalendarSaturday) { + return self.calendar.appearance.saturdayColor; + } + return self.calendar.appearance.titleDefaultColor; + +} + + +- (FSCalendarCellDay)getDayType:(NSString *)day { + if([day isEqualToString:@"일"]){ + return FSCalendarSunday; + } else if([day isEqualToString:@"토"]){ + return FSCalendarSaturday; + } + return FSCalendarNormalDay; +} + @end