Swift - 给图片(imageView)添加阴影边框
发布时间:2020-12-14 01:31:32 所属栏目:百科 来源:网络整理
导读:有时为了突出图片,需要给图片添加阴影效果。通过UIImageView的layer阴影属性设置,可以很方便的实现这个功能。不仅是UIImageView,其他的UI控件也是可以设置阴影的。 import UIKit class ViewController: UIViewController { @IBOutlet weak var imageView1
有时为了突出图片,需要给图片添加阴影效果。通过UIImageView的layer阴影属性设置,可以很方便的实现这个功能。 不仅是UIImageView,其他的UI控件也是可以设置阴影的。 import UIKit class ViewController: UIViewController { @IBOutlet weak var imageView1: UIImageView! @IBOutlet weak var imageView2: UIImageView! @IBOutlet weak var button1: UIButton! override func viewDidLoad() { super.viewDidLoad() //图片添加阴影 self.imageView1.layer.shadowOpacity = 0.8 self.imageView1.layer.shadowColor = UIColor.blackColor().CGColor self.imageView1.layer.shadowOffset = CGSize(width: 1,height: 1) //图片添加阴影(透明背景) self.imageView2.layer.shadowOpacity = 0.8 self.imageView2.layer.shadowColor = UIColor.blackColor().CGColor self.imageView2.layer.shadowOffset = CGSize(width: 1,height: 1) self.imageView2.layer.shadowRadius = 1 //按钮添加阴影 self.button1.layer.shadowOpacity = 0.8 self.button1.layer.shadowColor = UIColor.blackColor().CGColor self.button1.layer.shadowOffset = CGSize(width: 1,height: 1) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |