更新时间:2021-07-14 22:11:53
以下代码片段为 v
添加了边框、边框半径和阴影,一个 UIView
:
The following code snippet adds a border, border radius, and drop shadow to v
, a UIView
:
// border radius
[v.layer setCornerRadius:30.0f];
// border
[v.layer setBorderColor:[UIColor lightGrayColor].CGColor];
[v.layer setBorderWidth:1.5f];
// drop shadow
[v.layer setShadowColor:[UIColor blackColor].CGColor];
[v.layer setShadowOpacity:0.8];
[v.layer setShadowRadius:3.0];
[v.layer setShadowOffset:CGSizeMake(2.0, 2.0)];
Swift 5 版本:
Swift 5 Version :
// border radius
v.layer.cornerRadius = 30.0
// border
v.layer.borderColor = UIColor.lightGray.cgColor
v.layer.borderWidth = 1.5
// drop shadow
v.layer.shadowColor = UIColor.black.cgColor
v.layer.shadowOpacity = 0.8
v.layer.shadowRadius = 3.0
v.layer.shadowOffset = CGSize(width: 2.0, height: 2.0)
您可以调整设置以满足您的需要.
You can adjust the settings to suit your needs.
此外,将 QuartzCore 框架添加到您的项目中,并且:
Also, add the QuartzCore framework to your project and:
#import <QuartzCore/QuartzCore.h>
请参阅我的其他答案关于masksToBounds
.
注意
这可能不适用于所有情况.如果您发现此方法干扰了您正在执行的其他绘图操作,请参阅此答案.
This may not work in all cases. If you find that this method interferes with other drawing operations that you are performing, please see this answer.