日历FSCalendar中单元格的圆形边框

时间:2017-10-12 12:31:57

标签: ios swift calendar

我正在尝试为每个UIView添加边框。第一个和最后一个选定的日期应该有圆角,但是圆角延伸应用的遮罩会将其裁剪掉。

我尝试了许多其他解决方案,但这个似乎是最接近真实的。

请原谅我糟糕的英语。

extension FSCalendarCell {

    func changeCellStyle(isSelected:Bool, firstIndex:Bool, lastIndex:Bool, color:UIColor){

        let v = UIView(frame: CGRect(x: 0,y: 0,width: self.bounds.width,height: self.bounds.height))

        v.center = self.contentView.center
        v.backgroundColor = UIColor.red
        if firstIndex {
            v.addBorder(edges: [.top,.bottom,.left], color: UIColor.blue, thickness: 2)
            v.roundCorners([.topLeft, .bottomLeft], radius: 10)
        }else if lastIndex {
            v.addBorder(edges: [.top,.bottom,.right], color: UIColor.blue, thickness: 2)
            v.roundCorners([.topRight, .bottomRight], radius: 10)
        }else{
            v.addBorder(edges: [.top,.bottom], color: UIColor.blue, thickness: 2)
        }

        self.contentView.insertSubview(v, at: 0)
    }
}

2 个答案:

答案 0 :(得分:0)

尝试添加

v.layer.cornerRadius = v.frame.size.width/2
v.layer.maskToBounds = true

答案 1 :(得分:-1)

我认为你可以这样做:

self.(calendar).clipsToBounds