Commit 6429fc57 authored by lujunye's avatar lujunye

日历选择添加背景色

parent 299de975
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "1.000",
"green" : "0.933",
"red" : "0.878"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "1.000",
"green" : "0.933",
"red" : "0.878"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
...@@ -23,6 +23,8 @@ class DIYCalendarCell: FSCalendarCell { ...@@ -23,6 +23,8 @@ class DIYCalendarCell: FSCalendarCell {
weak var selectionLayer: CAShapeLayer! weak var selectionLayer: CAShapeLayer!
weak var selectionLayer2: CAShapeLayer!
var selectionType: SelectionType = .none { var selectionType: SelectionType = .none {
didSet { didSet {
setNeedsLayout() setNeedsLayout()
...@@ -36,8 +38,8 @@ class DIYCalendarCell: FSCalendarCell { ...@@ -36,8 +38,8 @@ class DIYCalendarCell: FSCalendarCell {
override init(frame: CGRect) { override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)
let color = UIColor.init(named: "蓝色字体颜色") let color = UIColor.init(named: "蓝色字体颜色")
// //选中layer // //选中layer
let selectionLayer = CAShapeLayer() let selectionLayer = CAShapeLayer()
selectionLayer.fillColor = color?.cgColor selectionLayer.fillColor = color?.cgColor
...@@ -45,49 +47,71 @@ class DIYCalendarCell: FSCalendarCell { ...@@ -45,49 +47,71 @@ class DIYCalendarCell: FSCalendarCell {
self.contentView.layer.insertSublayer(selectionLayer, below: self.titleLabel!.layer) self.contentView.layer.insertSublayer(selectionLayer, below: self.titleLabel!.layer)
self.selectionLayer = selectionLayer self.selectionLayer = selectionLayer
self.shapeLayer.isHidden = true self.shapeLayer.isHidden = true
//下面代码为添加选中日期背景色
let selectionLayer2 = CAShapeLayer()
selectionLayer2.fillColor = color?.cgColor
selectionLayer2.actions = ["hidden": NSNull()]
self.contentView.layer.insertSublayer(selectionLayer2, below: selectionLayer)
self.selectionLayer2 = selectionLayer2
} }
override func layoutSubviews() { override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
self.selectionLayer.frame = self.contentView.bounds self.selectionLayer.frame = self.contentView.bounds
let color = UIColor.white let color = UIColor.white
self.selectionLayer.fillColor = color.cgColor self.selectionLayer.fillColor = color.cgColor
//下面代码为添加选中日期背景色
self.selectionLayer2.fillColor = color.cgColor
self.selectionLayer2.frame = self.contentView.bounds
if selectionType == .middle { if selectionType == .middle {
print("middle--middle") print("middle--middle")
self.titleLabel.textColor = UIColor.init(named: "蓝色字体颜色") self.titleLabel.textColor = UIColor.init(named: "蓝色字体颜色")
let color = UIColor.white // let color = UIColor.white
self.selectionLayer.fillColor = color.cgColor // self.selectionLayer.fillColor = color.cgColor
self.selectionLayer.path = UIBezierPath(rect: self.selectionLayer.bounds).cgPath // self.selectionLayer.path = UIBezierPath(rect: self.selectionLayer.bounds).cgPath
//下面代码为添加选中日期背景色
self.selectionLayer.fillColor = UIColor(named: "#E0EEFF")?.cgColor
let bounds = CGRect(x: 0, y: 2, width: self.selectionLayer.bounds.size.width, height: self.selectionLayer.bounds.height - 8)
self.selectionLayer.path = UIBezierPath(rect: bounds).cgPath
} }
else if selectionType == .leftBorder { else if selectionType == .leftBorder {
self.titleLabel.textColor = UIColor.white self.titleLabel.textColor = UIColor.white
self.selectionLayer.fillColor = UIColor(named: "蓝色字体颜色")?.cgColor
let color = UIColor.init(named: "蓝色字体颜色")
self.selectionLayer.fillColor = color?.cgColor
let diameter: CGFloat = min(self.selectionLayer.frame.height, self.selectionLayer.frame.width) let diameter: CGFloat = min(self.selectionLayer.frame.height, self.selectionLayer.frame.width)
self.selectionLayer.path = UIBezierPath(ovalIn: CGRect(x: self.bounds.width / 2 - diameter / 2 + 2, y: self.bounds.height / 2 - diameter / 2 - 1, width: diameter - 4, height: diameter - 4)).cgPath self.selectionLayer.path = UIBezierPath(ovalIn: CGRect(x: self.bounds.width / 2 - diameter / 2 + 2, y: self.bounds.height / 2 - diameter / 2 - 1, width: diameter - 4, height: diameter - 4)).cgPath
//下面代码为添加选中日期背景色
let bounds = CGRect(x: self.selectionLayer2.bounds.size.width*0.5, y: 2, width: self.selectionLayer2.bounds.size.width, height: self.selectionLayer2.bounds.height - 8)
self.selectionLayer2.fillColor = UIColor(named: "#E0EEFF")?.cgColor
self.selectionLayer2.path = UIBezierPath(rect: bounds).cgPath
print("leftBorder--leftBorder") print("leftBorder--leftBorder")
} }
else if selectionType == .rightBorder { else if selectionType == .rightBorder {
print("rightBorder--rightBorder")
self.titleLabel.textColor = UIColor.white self.titleLabel.textColor = UIColor.white
let color = UIColor.init(named: "蓝色字体颜色") self.selectionLayer.fillColor = UIColor(named: "蓝色字体颜色")?.cgColor
self.selectionLayer.fillColor = color?.cgColor
let diameter: CGFloat = min(self.selectionLayer.frame.height, self.selectionLayer.frame.width) let diameter: CGFloat = min(self.selectionLayer.frame.height, self.selectionLayer.frame.width)
self.selectionLayer.path = UIBezierPath(ovalIn: CGRect(x: self.bounds.width / 2 - diameter / 2 + 2, y: self.bounds.height / 2 - diameter / 2 - 1, width: diameter - 4, height: diameter - 4)).cgPath self.selectionLayer.path = UIBezierPath(ovalIn: CGRect(x: self.bounds.width / 2 - diameter / 2 + 2, y: self.bounds.height / 2 - diameter / 2 - 1, width: diameter - 4, height: diameter - 4)).cgPath
//下面代码为添加选中日期背景色
let bounds = CGRect(x: 0, y: 2, width: self.selectionLayer2.bounds.size.width*0.5, height: self.selectionLayer2.bounds.height - 8)
self.selectionLayer2.fillColor = UIColor(named: "#E0EEFF")?.cgColor
self.selectionLayer2.path = UIBezierPath(rect: bounds).cgPath
}else if selectionType == .single { }else if selectionType == .single {
let color = UIColor.init(named: "蓝色字体颜色") self.selectionLayer.fillColor = UIColor.init(named: "蓝色字体颜色")?.cgColor
self.selectionLayer.fillColor = color?.cgColor
let diameter: CGFloat = min(self.selectionLayer.frame.height, self.selectionLayer.frame.width) let diameter: CGFloat = min(self.selectionLayer.frame.height, self.selectionLayer.frame.width)
self.selectionLayer.path = UIBezierPath(ovalIn: CGRect(x: self.bounds.width / 2 - diameter / 2 + 2, y: self.bounds.height / 2 - diameter / 2 - 1, width: diameter - 4, height: diameter - 4)).cgPath self.selectionLayer.path = UIBezierPath(ovalIn: CGRect(x: self.bounds.width / 2 - diameter / 2 + 2, y: self.bounds.height / 2 - diameter / 2 - 1, width: diameter - 4, height: diameter - 4)).cgPath
print("single--single") print("single--single")
self.titleLabel.textColor = UIColor.white self.titleLabel.textColor = UIColor.white
//下面代码为添加选中日期背景色
self.selectionLayer2.fillColor = UIColor.white.cgColor
self.selectionLayer2.path = UIBezierPath(rect: bounds).cgPath
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment