有没有一种方法可以模糊/淡化UIView的边框?
到目前为止,我在核心图形方面做得很少或没有。
有没有一种方法可以模糊/淡化UIView的边框?
到目前为止,我在核心图形方面做得很少或没有。
#include <QuartzCore/QuartzCore.h>
...
CALayer *layer = myView.layer;
layer.shadowOpacity = .5;
layer.shadowColor = [[UIColor blackColor] CGColor];
layer.shadowOffset = CGSizeMake(0,0);
layer.shadowRadius = 10;
添加一个使用Swift版本的示例:
btnSignIn.layer.cornerRadius = btnSignIn.frame.height * 0.5
btnSignIn.layer.shadowColor = UIColor.darkGray.cgColor
btnSignIn.layer.shadowRadius = 4.0
btnSignIn.layer.shadowOpacity = 1.0
btnSignIn.layer.shadowOffset = CGSize(width: 0, height: 0)
结果:
请记住,如果您在IB编辑器中更改阴影设置,它将更改文本的阴影而不是视图的边框。
此外,您可以创建一个类并在IB Builder中设置它:
class UIRoundedWhiteButton: UIButton {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
layer.cornerRadius = frame.height * 0.5
layer.shadowColor = UIColor.darkGray.cgColor
layer.shadowRadius = 4.0
layer.shadowOpacity = 1.0
layer.shadowOffset = CGSize(width: 0, height: 0)
}...