编辑:
以下是我在Sketch中的设置:
这就是我希望我的阴影看起来像:
这里现在是什么样子的:
注意,你必须点击图片实际看到阴影.
我的代码如下:
func setupLayer(){ vIEw.layer.cornerRadius = 2 vIEw.layer.shadowcolor = colors.Shadow.CGcolor vIEw.layer.shadowOffset = CGSize(wIDth: 0,height: 1) vIEw.layer.shadowOpacity = 0.9 vIEw.layer.shadowRadius = 5}解决方法 你可以试试这个….你可以玩这些价值观.
shadowRadius指定模糊量. shadowOffset指示阴影在哪里.
Swift 2.0
let radius: CGfloat = demoVIEw.frame.wIDth / 2.0 //change it to .height if you need spread for heightlet shadowPath = UIBezIErPath(rect: CGRect(x: 0,y: 0,wIDth: 2.1 * radius,height: demoVIEw.frame.height))//Change 2.1 to amount of spread you need and for height replace the code for heightdemoVIEw.layer.cornerRadius = 2demoVIEw.layer.shadowcolor = UIcolor.blackcolor().CGcolordemoVIEw.layer.shadowOffset = CGSize(wIDth: 0.5,height: 0.4) //Here you control x and ydemoVIEw.layer.shadowOpacity = 0.5demoVIEw.layer.shadowRadius = 5.0 //Here your control your blurdemoVIEw.layer.masksToBounds = falsedemoVIEw.layer.shadowPath = shadowPath.CGPath
Swift 3.0
let radius: CGfloat = demoVIEw.frame.wIDth / 2.0 //change it to .height if you need spread for height let shadowPath = UIBezIErPath(rect: CGRect(x: 0,height: demoVIEw.frame.height)) //Change 2.1 to amount of spread you need and for height replace the code for heightdemoVIEw.layer.cornerRadius = 2demoVIEw.layer.shadowcolor = UIcolor.black.cgcolordemoVIEw.layer.shadowOffset = CGSize(wIDth: 0.5,height: 0.4) //Here you control x and ydemoVIEw.layer.shadowOpacity = 0.5demoVIEw.layer.shadowRadius = 5.0 //Here your control your blurdemoVIEw.layer.masksToBounds = falsedemoVIEw.layer.shadowPath = shadowPath.cgPath
Example with spread
To create a basic shadow
demoVIEw.layer.cornerRadius = 2 demoVIEw.layer.shadowcolor = UIcolor.blackcolor().CGcolor demoVIEw.layer.shadowOffset = CGSizeMake(0.5,4.0); //Here your control your spread demoVIEw.layer.shadowOpacity = 0.5 demoVIEw.layer.shadowRadius = 5.0 //Here your control your blur
总结Basic Shadow example in Swift 2.0
以上是内存溢出为你收集整理的ios – 如何控制阴影传播和模糊?全部内容,希望文章能够帮你解决ios – 如何控制阴影传播和模糊?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)