You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.5 KiB
92 lines
2.5 KiB
// |
|
// DateSelectView.swift |
|
// HPlusFit |
|
// |
|
// Created by lemo. on 2019/9/17. |
|
// Copyright © 2019 lemo. All rights reserved. |
|
// |
|
|
|
import UIKit |
|
|
|
typealias DateSelectViewClosure = (String, Bool) -> Void |
|
|
|
class DateSelectView: UIView { |
|
|
|
var dateStr: String? { |
|
didSet { |
|
setDateStr() |
|
} |
|
} |
|
|
|
var dateSelectClosure: DateSelectViewClosure? |
|
|
|
let leftArrowBtn = UIButton().then{ |
|
$0.setImage(R.image.day_before(), for: .normal) |
|
$0.contentMode = .scaleAspectFit |
|
} |
|
|
|
let rightArrowBtn = UIButton().then{ |
|
$0.setImage(R.image.day_after(), for: .normal) |
|
$0.contentMode = .scaleAspectFit |
|
} |
|
|
|
let dateLabel = UILabel().then { |
|
$0.font = SystemMediumFont(18) |
|
$0.textColor = kHexColor(0x666666) |
|
$0.textAlignment = .center |
|
} |
|
|
|
override init(frame: CGRect) { |
|
super.init(frame: frame) |
|
self.addSubview(dateLabel) |
|
self.addSubview(leftArrowBtn) |
|
self.addSubview(rightArrowBtn) |
|
leftArrowBtn.addTarget(self, action: #selector(backwardAction), for: UIControl.Event.touchUpInside) |
|
rightArrowBtn.addTarget(self, action: #selector(forwardAction), for: UIControl.Event.touchUpInside) |
|
} |
|
|
|
required init?(coder aDecoder: NSCoder) { |
|
fatalError("init(coder:) has not been implemented") |
|
} |
|
|
|
override func layoutSubviews() { |
|
super.layoutSubviews() |
|
|
|
dateLabel.snp.makeConstraints { (make) in |
|
make.centerX.equalToSuperview() |
|
make.centerY.equalToSuperview() |
|
} |
|
|
|
leftArrowBtn.snp.makeConstraints { (make) in |
|
make.right.equalTo(dateLabel.snp.left).offset(-kScaleWidth(15.0)) |
|
make.width.height.equalTo(kScaleWidth(40.0)) |
|
make.centerY.equalToSuperview() |
|
} |
|
|
|
rightArrowBtn.snp.makeConstraints { (make) in |
|
make.left.equalTo(dateLabel.snp.right).offset(kScaleWidth(15.0)) |
|
make.width.height.equalTo(kScaleWidth(40.0)) |
|
make.centerY.equalToSuperview() |
|
} |
|
} |
|
|
|
@objc func backwardAction() { |
|
if let selectClosure = self.dateSelectClosure { |
|
selectClosure(self.dateStr!,false) |
|
} |
|
} |
|
|
|
@objc func forwardAction() { |
|
if let selectClosure = self.dateSelectClosure { |
|
selectClosure(self.dateStr!,true) |
|
} |
|
} |
|
} |
|
|
|
extension DateSelectView { |
|
func setDateStr() { |
|
if let dateStr = self.dateStr { |
|
dateLabel.text = dateStr |
|
} |
|
} |
|
}
|
|
|