ios – 如何控制阴影传播和模糊?

ios – 如何控制阴影传播和模糊?,第1张

概述我已经在草图中设计了UI元素,其中一个具有模糊1和展开0.的阴影.我查看了视图层属性的文档,层没有任何名为spread或blur或任何等同物(唯一的控件是只是shadowOpacity)如何控制像模糊和传播的东西? 编辑: 以下是我在Sketch中的设置: 这就是我希望我的阴影看起来像: 这里现在是什么样子的:  注意,你必须点击图片实际看到阴影. 我的代码如下: func setupLayer( 我已经在草图中设计了UI元素,其中一个具有模糊1和展开0.的阴影.我查看了视图层属性的文档,层没有任何名为spread或blur或任何等同物(唯一的控件是只是shadowOpacity)如何控制像模糊和传播的东西?

编辑:

以下是我在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 – 如何控制阴影传播和模糊?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1115163.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存