TIL77 ✨

YaR Lab·2023년 8월 8일
0

TIL✨

목록 보기
65/135
post-thumbnail

🗓️23.08.08

📌 Truth

Truth는 각각의 시스템이나 개체가 가지고 있는 자신만의 현재 상태나 데이터를 말함

📌 Centralize

중앙 집중화

📌 UIBarButtonItem

navigationItem.rightBarButtonItem

let setupSearchDateButton = UIBarButtonItem(title: "날짜선택", style: .plain, target: self, action: #selector(didTapSetupSearchDateButton))

📌 modal

let childVC = ChildViewController()
    
// fullScreen is default value
childVC.modalPresentationStyle = .fullScreen
    
self.present(childVC, animated: true, completion: nil)

📌 NSCache

extension NSCache {
    static let shared = NSCache<NSString, UIImage>()
}

📌 UICalendarView

  • 날짜별 장식이 있는 달력을 표시하고, 사용자가 단일 날짜여러 날짜를 선택할 수 있는 뷰
  • 달력 뷰는 날짜의 표시와 선택만을 위해 사용
  • 달력 뷰를 사용하여 사용자에게 특정 날짜에 추가 정보(예: 예정된 이벤트)를 보여줄 때 사용자 정의한 장식을 사용
  • 달력 뷰를 이용하여 사용자가 특정 날짜 하나, 여러 날짜도 선택할 수 있도록 설정할 수 있습니다.
  • 날짜 선택 없음도 구현 가능
  • 달력 뷰는 사용자의 현재 달력과 로케일을 선택함
  • 사용자가 앱에서 다른 달력이나 로케일을 선택할 수 있는 경우, 달력 뷰를 해당 선택사항을 사용하도록 구성 해야함

1️⃣ 시작 날짜 설정

calendarView.visibleDateComponents = DateComponents(calendar: Calendar(identifier: .gregorian), year: 2022, month: 6, day: 6)

2️⃣ 최소 또는 최대 날짜를 제한

availableDateRange 프로퍼티
DateInterval 타입

let fromDateComponents = DateComponents(calendar: Calendar(identifier: .gregorian), year: 2022, month: 1, day: 1)
let toDateComponents = DateComponents(calendar: Calendar(identifier: .gregorian), year: 2022, month: 12, day: 31)


guard let fromDate = fromDateComponents.date, let toDate = toDateComponents.date else {
    return
}


let calendarViewDateRange = DateInterval(start: fromDate, end: toDate)
calendarView.availableDateRange = calendarViewDateRange

3️⃣ 특정한 날짜에 장식 표현

잠시 skip

4️⃣ 날짜 선택

  • 단일 날짜, 여러 날짜 또는 아무 날짜도 선택할 수 있도록 구현
  • 먼저 어떤 유형의 날짜 선택을 원하는지 결정
  • 그런 다음 해당 유형에 대한 선택 객체와 델리게이트를 생성하고, 이를 캘린더 뷰의 selectionBehavior에 할당
let dateSelection = UICalendarSelectionSingleDate(delegate: self)
calendarView.selectionBehavior = dateSelection
  • 이후 사용자는 캘린더 뷰에서 날짜를 선택할 수 있음
  • 선택된 날짜를 설정할 수 있음
dateSelection.selectedDate(DateComponents(calendar: Calendar(identifier: .gregorian), year:2022, month: 6, day: 6))
  • 선택 방법에 대한 델리게이트 메서드를 구현하여 날짜 선택 처리를 사용자 정의
func dateSelection(_ selection: UICalendarSelectionSingleDate, canSelectDate dateComponents: DateComponents?) -> Bool {
    // Return `true` to allow a date selection; a nil date clears the selection.
    // Require a date selection by returning false if dateComponents is nil.
    return dateComponents != nil
}

피드백

모던 컬렉션 뷰
디폴데이터소스 =
wwdc는 선택이 아님

0개의 댓글