带有褪色边缘的按钮下方的 BlurView
BlurView below a button with fading edges
我在 mapView 的顶部创建了一个按钮。
为了使该按钮更明显,我在该按钮下方添加了一个模糊视图。
我不喜欢模糊视图的锐利边缘。
如何让模糊淡出慢慢过渡到 mapView?
编辑: 更具体一点。我的意思是带有圆角的褪色模糊渐变。
你试过cornerRadius
属性了吗?那应该去除锋利的边缘
我认为这可以帮助你,首先你需要子类化你的按钮并在 drawRect
中添加此代码并将 UIColor.blueColor().CGColor
替换为 yourColor.CGColor
class UICustomBackgroundButton: UIButton {
override func draw(_ rect: CGRect) {
// Drawing code
super.draw(rect)
let ctx = UIGraphicsGetCurrentContext();
let path = CGPath(roundedRect: rect.insetBy(dx: self.frame.size.height/4, dy: self.frame.size.height/4) , cornerWidth: self.frame.size.height/8, cornerHeight: self.frame.size.height/8, transform: nil)
ctx?.setShadow(offset: CGSize.zero, blur: self.frame.size.height/4, color: UIColor.blue.cgColor);
ctx?.setFillColor(UIColor.blue.cgColor);
//if number of cicles is our glow is darker
for _ in 0..<6
{
ctx?.addPath(path);
ctx?.fillPath();
}
}
}
希望对您有所帮助。
这是它的样子
我在 mapView 的顶部创建了一个按钮。 为了使该按钮更明显,我在该按钮下方添加了一个模糊视图。 我不喜欢模糊视图的锐利边缘。 如何让模糊淡出慢慢过渡到 mapView?
编辑: 更具体一点。我的意思是带有圆角的褪色模糊渐变。
你试过cornerRadius
属性了吗?那应该去除锋利的边缘
我认为这可以帮助你,首先你需要子类化你的按钮并在 drawRect
中添加此代码并将 UIColor.blueColor().CGColor
替换为 yourColor.CGColor
class UICustomBackgroundButton: UIButton {
override func draw(_ rect: CGRect) {
// Drawing code
super.draw(rect)
let ctx = UIGraphicsGetCurrentContext();
let path = CGPath(roundedRect: rect.insetBy(dx: self.frame.size.height/4, dy: self.frame.size.height/4) , cornerWidth: self.frame.size.height/8, cornerHeight: self.frame.size.height/8, transform: nil)
ctx?.setShadow(offset: CGSize.zero, blur: self.frame.size.height/4, color: UIColor.blue.cgColor);
ctx?.setFillColor(UIColor.blue.cgColor);
//if number of cicles is our glow is darker
for _ in 0..<6
{
ctx?.addPath(path);
ctx?.fillPath();
}
}
}
希望对您有所帮助。
这是它的样子