我正在尝试创建一个简单的圆形按钮并在此按钮内放置一个三角形,实际上它是一个播放按钮。问题是当我将 BlurEffect 添加到按钮时,它总是在顶部并且会隐藏三角形。有没有办法在模糊效果上方添加三角形?
import UIKit
@IBDesignable
class CirclePlayButton: UIButton {
let blur = UIBlurEffect(style: .Light)
override func drawRect(rect: CGRect) {
let blurEffect = UIVisualEffectView(effect: blur)
blurEffect.alpha = 0.9
//self.addSubview(blurEffect)
self.insertSubview(blurEffect, atIndex: 0)
let path = UIBezierPath(ovalInRect: rect)
blurEffect.frame = path.bounds
let mask = CAShapeLayer()
mask.path = path.CGPath
blurEffect.layer.mask = mask
let trianglePath = UIBezierPath()
trianglePath.lineWidth = 2
trianglePath.moveToPoint(CGPoint(x: bounds.width*1/4+5, y: bounds.height/4))
trianglePath.addLineToPoint(CGPoint(x: bounds.width*3/4+5, y: bounds.height/2))
trianglePath.addLineToPoint(CGPoint(x: bounds.width*1/4+5, y: bounds.height*3/4))
trianglePath.addLineToPoint(CGPoint(x: bounds.width*1/4+5, y: bounds.height/4))
UIColor.blackColor().setStroke()
trianglePath.stroke()
}
}
提前致谢。