Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit a1ad633

Browse files
committed
update 1.1.0
- add calendar type (normal, limited) - remove duplicated code - change indentation style (tab -> space) - update README
1 parent c6f4bce commit a1ad633

File tree

9 files changed

+914
-755
lines changed

9 files changed

+914
-755
lines changed

Example/YYCalendar/Base.lproj/Main.storyboard

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,32 @@
5959
<action selector="showCalendar2:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="Ent-1k-B52"/>
6060
</connections>
6161
</button>
62+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Itb-Cl-UwP">
63+
<rect key="frame" x="46" y="332" width="283" height="40"/>
64+
<color key="backgroundColor" red="0.0" green="0.58980089430000004" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
65+
<constraints>
66+
<constraint firstAttribute="height" constant="40" id="xT7-Mb-u97"/>
67+
</constraints>
68+
<state key="normal" title="Show YYCalendar (limited period)">
69+
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
70+
</state>
71+
<connections>
72+
<action selector="showCalendar3:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="SO4-Nm-2ei"/>
73+
</connections>
74+
</button>
6275
</subviews>
6376
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
6477
<constraints>
6578
<constraint firstAttribute="trailingMargin" secondItem="Q6e-Su-w08" secondAttribute="trailing" constant="30" id="1h4-ti-2ZF"/>
79+
<constraint firstAttribute="trailingMargin" secondItem="Itb-Cl-UwP" secondAttribute="trailing" constant="30" id="A1c-JA-bQn"/>
6680
<constraint firstItem="Xon-wd-1Pm" firstAttribute="centerX" secondItem="kh9-bI-dsS" secondAttribute="centerX" id="Fbm-NH-u4g"/>
6781
<constraint firstItem="zaX-cJ-bCm" firstAttribute="centerX" secondItem="kh9-bI-dsS" secondAttribute="centerX" id="PP5-gl-iTI"/>
6882
<constraint firstItem="Q6e-Su-w08" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" constant="30" id="TTn-ZJ-2AC"/>
6983
<constraint firstItem="zaX-cJ-bCm" firstAttribute="top" secondItem="Xon-wd-1Pm" secondAttribute="bottom" constant="30" id="h1A-kY-C7T"/>
7084
<constraint firstAttribute="trailingMargin" secondItem="avE-zr-6kq" secondAttribute="trailing" constant="30" id="iYP-Yd-9ly"/>
85+
<constraint firstItem="Itb-Cl-UwP" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" constant="30" id="oCc-2o-Uzh"/>
7186
<constraint firstItem="Xon-wd-1Pm" firstAttribute="top" secondItem="jyV-Pf-zRb" secondAttribute="bottom" constant="50" id="oYP-a8-z7j"/>
87+
<constraint firstItem="Itb-Cl-UwP" firstAttribute="top" secondItem="Q6e-Su-w08" secondAttribute="bottom" constant="30" id="qDX-vN-b0i"/>
7288
<constraint firstItem="avE-zr-6kq" firstAttribute="top" secondItem="zaX-cJ-bCm" secondAttribute="bottom" constant="50" id="tI8-S5-REE"/>
7389
<constraint firstItem="Q6e-Su-w08" firstAttribute="top" secondItem="avE-zr-6kq" secondAttribute="bottom" constant="30" id="uQh-Cu-E3m"/>
7490
<constraint firstItem="avE-zr-6kq" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" constant="30" id="z7N-1W-kFL"/>

Example/YYCalendar/ViewController.swift

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,40 @@ import UIKit
1010
import YYCalendar
1111

1212
class ViewController: UIViewController {
13-
@IBOutlet weak var selectedDateLabel: UILabel!
13+
@IBOutlet weak var selectedDateLabel: UILabel!
1414

15-
override func viewDidLoad() {
16-
super.viewDidLoad()
17-
// Do any additional setup after loading the view, typically from a nib.
18-
}
15+
override func viewDidLoad() {
16+
super.viewDidLoad()
17+
// Do any additional setup after loading the view, typically from a nib.
18+
}
1919

20-
override func didReceiveMemoryWarning() {
21-
super.didReceiveMemoryWarning()
22-
// Dispose of any resources that can be recreated.
23-
}
20+
override func didReceiveMemoryWarning() {
21+
super.didReceiveMemoryWarning()
22+
// Dispose of any resources that can be recreated.
23+
}
2424

25-
@IBAction func showCalendar(_ sender: UIButton) {
26-
let calendar = YYCalendar(langType: .ENG, date: "07/01/2019", format: "MM/dd/yyyy", disableAfterToday: false) { date in
27-
self.selectedDateLabel.text = date
28-
}
25+
@IBAction func showCalendar(_ sender: UIButton) {
26+
let calendar = YYCalendar(langType: .ENG, date: "07/01/2019", format: "MM/dd/yyyy", disableAfterToday: false) { date in
27+
self.selectedDateLabel.text = date
28+
}
2929

30-
calendar.show()
31-
}
30+
calendar.show()
31+
}
3232

33-
@IBAction func showCalendar2(_ sender: UIButton) {
34-
let calendar = YYCalendar(langType: .KOR, date: "07/01/2019", format: "MM/dd/yyyy", disableAfterToday: true) { date in
35-
self.selectedDateLabel.text = date
36-
}
33+
@IBAction func showCalendar2(_ sender: UIButton) {
34+
let calendar = YYCalendar(langType: .KOR, date: "07/01/2019", format: "MM/dd/yyyy", disableAfterToday: true) { date in
35+
self.selectedDateLabel.text = date
36+
}
3737

38-
calendar.show()
39-
}
38+
calendar.show()
39+
}
40+
41+
@IBAction func showCalendar3(_ sender: UIButton) {
42+
let calendar = YYCalendar(langType: .KOR, date: "07/05/2019", minDate: "07/05/2019", maxDate: "07/15/2019", format: "MM/dd/yyyy") { date in
43+
self.selectedDateLabel.text = date
44+
}
45+
46+
calendar.show()
47+
}
4048
}
4149

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,31 @@ First of all, you can show the calendar as below:<br>
2828
2929
```swift
3030
let calendar = YYCalendar(langType: .ENG, date: "06/10/2019", format: "MM/dd/yyyy", disableAfterToday: false) { date in
31-
self.selectedDateLabel.text = date
31+
self.selectedDateLabel.text = date
3232
}
3333

3434
calendar.show()
3535
```
3636

37+
## Calendar Type
38+
39+
There are two types of calendar.
40+
41+
| calendarType | description |
42+
|---|---|
43+
| normal | you can select all of the date periods |
44+
| limited | you can limit selectable date periods |
45+
46+
```swift
47+
// normal type
48+
init(langType type: LangType, date: String, format: String, disableAfterToday: Bool, completion selectHandler: SelectHandler?)
49+
50+
// limited type
51+
init(langType type: LangType, date: String, minDate: String?, maxDate: String?, format: String, completion selectHandler: SelectHandler?)
52+
```
53+
54+
![normalType_Sample](https://raw.githubusercontent.com/DevYeom/YYCalendar/master/ScreenShot/normal_type.png) ![limitedType_Sample](https://raw.githubusercontent.com/DevYeom/YYCalendar/master/ScreenShot/limited_type.png)
55+
3756
## Language Type
3857

3958
Week label can be changed by selecting langType

ScreenShot/limited_type.png

11.2 KB
Loading

ScreenShot/normal_type.png

12.4 KB
Loading

YYCalendar.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'YYCalendar'
11-
s.version = '1.0.3'
11+
s.version = '1.1.0'
1212
s.swift_version = '5.0'
1313
s.summary = 'Very Simple and Useful Calendar'
1414

YYCalendar/Classes/DayButton.swift

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,51 @@ import Foundation
99

1010
@available(iOS 10.0, *)
1111
class DayButton: UIButton {
12-
let todayIconImage: UIImage? = UIImage(named: "today_icon", in: Bundle(for: DayButton.self), compatibleWith: nil)
13-
let selectedDayColor: UIColor = Useful.getUIColor(55, 137, 220)
14-
var beforeTextColor: UIColor = Useful.getUIColor(51, 51, 51)
15-
var todayIconImageView: UIImageView!
16-
17-
override init(frame: CGRect) {
18-
super.init(frame: frame)
19-
20-
setupTodayIcon()
21-
setupAutoLayout()
22-
23-
self.todayIconImageView.isHidden = true
24-
}
25-
26-
required init?(coder aDecoder: NSCoder) {
27-
super.init(coder: aDecoder)
28-
}
29-
30-
override var isHighlighted: Bool {
31-
willSet {
32-
beforeTextColor = titleLabel?.textColor ?? Useful.getUIColor(51, 51, 51)
33-
}
34-
35-
didSet {
36-
backgroundColor = isHighlighted ? selectedDayColor : UIColor.white
37-
titleLabel?.textColor = isHighlighted ? UIColor.white : beforeTextColor
38-
}
39-
}
40-
41-
func setupTodayIcon() {
42-
todayIconImageView = UIImageView.init()
43-
todayIconImageView.image = todayIconImage
44-
45-
self.addSubview(todayIconImageView)
46-
}
47-
48-
func setupAutoLayout() {
49-
self.titleLabel?.translatesAutoresizingMaskIntoConstraints = false
50-
self.todayIconImageView.translatesAutoresizingMaskIntoConstraints = false
51-
52-
self.titleLabel?.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
53-
self.titleLabel?.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
54-
self.todayIconImageView.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
55-
self.todayIconImageView.topAnchor.constraint(equalTo: (self.titleLabel?.bottomAnchor)!, constant: 2).isActive = true
56-
self.todayIconImageView.heightAnchor.constraint(equalToConstant: 5).isActive = true
57-
self.todayIconImageView.widthAnchor.constraint(equalTo: self.todayIconImageView.heightAnchor).isActive = true
58-
}
12+
let todayIconImage: UIImage? = UIImage(named: "today_icon", in: Bundle(for: DayButton.self), compatibleWith: nil)
13+
let selectedDayColor: UIColor = Useful.getUIColor(55, 137, 220)
14+
var beforeTextColor: UIColor = Useful.getUIColor(51, 51, 51)
15+
var todayIconImageView: UIImageView!
16+
17+
override init(frame: CGRect) {
18+
super.init(frame: frame)
19+
20+
setupTodayIcon()
21+
setupAutoLayout()
22+
23+
self.todayIconImageView.isHidden = true
24+
}
25+
26+
required init?(coder aDecoder: NSCoder) {
27+
super.init(coder: aDecoder)
28+
}
29+
30+
override var isHighlighted: Bool {
31+
willSet {
32+
beforeTextColor = titleLabel?.textColor ?? Useful.getUIColor(51, 51, 51)
33+
}
34+
35+
didSet {
36+
backgroundColor = isHighlighted ? selectedDayColor : UIColor.white
37+
titleLabel?.textColor = isHighlighted ? UIColor.white : beforeTextColor
38+
}
39+
}
40+
41+
func setupTodayIcon() {
42+
todayIconImageView = UIImageView.init()
43+
todayIconImageView.image = todayIconImage
44+
45+
self.addSubview(todayIconImageView)
46+
}
47+
48+
func setupAutoLayout() {
49+
self.titleLabel?.translatesAutoresizingMaskIntoConstraints = false
50+
self.todayIconImageView.translatesAutoresizingMaskIntoConstraints = false
51+
52+
self.titleLabel?.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
53+
self.titleLabel?.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
54+
self.todayIconImageView.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
55+
self.todayIconImageView.topAnchor.constraint(equalTo: (self.titleLabel?.bottomAnchor)!, constant: 2).isActive = true
56+
self.todayIconImageView.heightAnchor.constraint(equalToConstant: 5).isActive = true
57+
self.todayIconImageView.widthAnchor.constraint(equalTo: self.todayIconImageView.heightAnchor).isActive = true
58+
}
5959
}

0 commit comments

Comments
 (0)