边缘褪色的按钮下方的BlurView [英] BlurView below a button with fading edges
问题描述
我在mapView顶部创建了一个按钮. 为了使该按钮更加可见,我在该按钮下方添加了一个模糊视图. 我不喜欢模糊视图的锐利边缘. 如何使模糊效果逐渐淡出并过渡到mapView?
I created a button on top of my mapView. In order to make that Button more visible I added a blur view below that button. I don't like the sharp edges of my blur view. How do I make the blur fade out slowly transitioning into the mapView?
编辑:更具体.我的意思是带有圆角的渐隐模糊渐变.
To be more specific. I mean a fading blurred gradient with round corners.
推荐答案
我认为这可以为您提供帮助,首先您需要对按钮进行子类化,并在drawRect
中添加此代码,然后将UIColor.blueColor().CGColor
替换为yourColor.CGColor
I think this can help you, first you need subclass your button and add this code in drawRect
and replace UIColor.blueColor().CGColor
by 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();
}
}
}
希望这对您有所帮助.
I Hope this helps you.
这就是它的外观
这篇关于边缘褪色的按钮下方的BlurView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!