将 CSS 框阴影转换为 iOS 阴影 [英] Convert CSS Box Shadow to iOS Shadow

查看:40
本文介绍了将 CSS 框阴影转换为 iOS 阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何在 Objective-C 中将 box-shadow 转换为 UIButton 上的阴影?

例如这个阴影:

box-shadow: 2px 0 0 0 #46d466,-2px 0 0 #46d466,0 2px 4px 0 rgba(0,0,0,.1),0 2px 8px 0 rgba(70,212,102,.7);

解决方案

UIButton 有一个 CALayer 类型的特殊属性图层.图层属性非常适合许多快速特效,一些是内置的,就像阴影是这些内置效果之一.

请找到以下代码.

btn.layer.shadowColor = [UIColor grayColor].CGColor;btn.layer.shadowOffset = CGSizeMake(3.0, 3.0);btn.layer.shadowOpacity = 2.0;btn.layer.shadowRadius = 2.0;

<块引用>

  1. shadowOffset :用于创建阴影的模糊半径.默认值到 (0, -3).
  2. shadowOpacity : 图层阴影的不透明度.默认为 0.
  3. shadowRadius :用于渲染的模糊半径(以点为单位)图层的阴影.

有关更多信息,请查看

您还可以更改阴影的半径,这会影响阴影的模糊程度.

btn.layer.shadowRadius = 10.0;

希望它对你有用!!!

Does anyone know how I can convert a box-shadow to a shadow on a UIButton in Objective-C?

For example this shadow:

box-shadow: 2px 0 0 0 #46d466,-2px 0 0 0 #46d466,0 2px 4px 0 rgba(0,0,0,.1),0 2px 8px 0 rgba(70,212,102,.7);

解决方案

UIButton have a special property layer of type CALayer.The layer property is great for many quick special effects, some built-in, like shadows are one of those built-in effects.

Please find the below code.

btn.layer.shadowColor = [UIColor grayColor].CGColor;
btn.layer.shadowOffset = CGSizeMake(3.0, 3.0);
btn.layer.shadowOpacity = 2.0;
btn.layer.shadowRadius = 2.0;

  1. shadowOffset : The blur radius used to create the shadow. Defaults to (0, -3).
  2. shadowOpacity : The opacity of the layer’s shadow. Defaults to 0.
  3. shadowRadius : The blur radius (in points) used to render the layer’s shadow.

For more information please review the API on developer site.

Or also you can change the offset of shadow.

btn.layer.shadowOffset = CGSizeMake(10.0, 10.0);

You can also change the radius of the shadow which affects how blurry the shadow appears.

btn.layer.shadowRadius = 10.0;

Hope it will work for you!!!

这篇关于将 CSS 框阴影转换为 iOS 阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆