2017-10-12 161 views
0

我正在嘗試爲每個UIView添加邊框。第一個和最後一個選定的日期應該有圓角,但是由圓角擴展應用的遮罩會將其裁剪掉。日曆中的單元格的邊框邊框FSCalendar

我已經嘗試了許多其他的解決方案,但這一個似乎是最接近真實的。

對不起,我英語不好。

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) 
    } 
} 
+0

請附上屏幕截圖 –

+0

重複的https://stackoverflow.com/questions/3330378/cocoa-touch-how-to-change-uiviews-border-color厚度 –

+0

[可可觸摸:如何更改UIView的邊框顏色和厚度的可能的重複?](https://stackoverflow.com/questions/3330378/cocoa-touch-how-to-change-uiviews-border-color厚度) –

回答

0

嘗試添加

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