要制作圆圈视图,必须执行
shapeView.layer.cornerRadius = CGFloat(width)/2.0
所以我将这个逻辑扩展为椭圆形视图
if width >= height {
shapeView.layer.cornerRadius = CGFloat(width)/2.0
} else{
shapeView.layer.cornerRadius = CGFloat(height)/2.0
}
除了我的椭圆形视图有尖端,你可以看到here.
我的问题是:如何摆脱尖端并使它们成为圆形?
如果我有任何疑虑,请使用:
答案 0 :(得分:7)
使用var templates = template.New("template").Funcs(template.FuncMap{
"authenticated": func() bool {
log.Println("Was I called?")
return false
},
"username": func() string {
return ""
},
})
作为图层蒙版:
CAShapeLayer
演示:
class OvalView: UIView {
override func layoutSubviews() {
super.layoutSubviews()
layoutOvalMask()
}
private func layoutOvalMask() {
let mask = self.shapeMaskLayer()
let bounds = self.bounds
if mask.frame != bounds {
mask.frame = bounds
mask.path = CGPathCreateWithEllipseInRect(bounds, nil)
}
}
private func shapeMaskLayer() -> CAShapeLayer {
if let layer = self.layer.mask as? CAShapeLayer {
return layer
}
let layer = CAShapeLayer()
layer.fillColor = UIColor.blackColor().CGColor
self.layer.mask = layer
return layer
}
}
结果:
答案 1 :(得分:0)