Swift3实现图片圆角、阴影、边框

xiaoxiao2021-02-28  84

一、IB实现图片圆角

打开 .    Main.storyboard   选择要设置圆角的  ImageView   在右侧的身份设置检查器中选择   User Defined Runtime Attributes  中添加如图所示代码

其中CornerRadius表示的是圆角的半径    Type表示圆角半径的值的类型     Value表示的是圆角半径值的大小

二、代码实现

self.areaImageView.layer.cornerRadius = 30//30表示你要设置半径的大小 self.areaImageView.clipsToBounds = true //设置超出部分裁剪,必须设置圆角才能生效

let testView = UIView(frame: CGRect(x: 20, y: 20, width: 100, height: 100)) testView.backgroundColor = .red // 设置边框 testView.layer.borderWidth = 10 testView.layer.borderColor = UIColor.brown.cgColor // 设置阴影 testView.layer.shadowOpacity = 0.5 //不透明度 testView.layer.shadowOffset = CGSize(width: 0, height: 50) // 设置阴影的偏移量 testView.layer.shadowRadius = 50 //设置阴影所照射的范围 // 设置圆角 testView.layer.cornerRadius = 50 testView.clipsToBounds = true

转载请注明原文地址: https://www.6miu.com/read-67938.html

最新回复(0)