忘れないようにメモ
import Foundation
@IBDesignable
class TLViewRadiusMulti: UIView {
//丸み
@IBInspectable var Radius : CGFloat = 0.0 {
didSet {
self.applyRadius();
}
}
//左上
@IBInspectable var TopLeft : Bool = false {
didSet {
self.applyRadius();
}
}
//右上
@IBInspectable var TopRight : Bool = false {
didSet {
self.applyRadius();
}
}
//左下
@IBInspectable var BottomLeft : Bool = false {
didSet {
self.applyRadius();
}
}
//右下
@IBInspectable var BottomRight : Bool = false {
didSet {
self.applyRadius();
}
}
private func applyRadius(){
var corners : UIRectCorner = UIRectCorner();
if TopLeft {
corners = corners.union(.TopLeft);
}
if TopRight {
corners = corners.union(.TopRight);
}
if BottomLeft {
corners = corners.union(.BottomLeft);
}
if BottomRight {
corners = corners.union(.BottomRight);
}
if corners.rawValue == 0 {
return ;
}
let maskPath = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSizeMake(Radius, Radius));
let maskLayer = CAShapeLayer();
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
}
}