最近比较忙,想要做的事情有很多,能做出来的就只有一部份,我觉得也许是我没有计划和规律造成的,我需要坚持下去,今天写了一个swift2.0给按钮或者图片添加阴影的效果,就当做笔记吧:-)
Swift Code:
let image1 = UIImageView(frame: CGRectMake(,,self.view.frame.width-,))
image1.image = UIImage(named: "sea.jpg")
self.view.addSubview(image1)
//为图片添加阴影
image1.layer.shadowOpacity = 0.8//设置阴影透明度
image1.layer.shadowColor = UIColor.blackColor().CGColor
image1.layer.shadowOffset = CGSize(width: , height: )//设置阴影偏移量 let image2 = UIImageView(image: UIImage(named: "wenzi"))
image2.frame = CGRectMake(, , self.view.frame.width-, )
self.view.addSubview(image2)
//为图片添加阴影(透明背景)
image2.layer.shadowOpacity = 0.8
image2.layer.shadowColor = UIColor.blackColor().CGColor
image2.layer.shadowOffset = CGSize(width: , height: )
image2.layer.shadowRadius = let button = UIButton(frame: CGRectMake(, , , ))
button.backgroundColor = UIColor(red:0.02, green:0.48, blue:, alpha:)
//设置圆角
button.layer.borderColor = UIColor.whiteColor().CGColor
button.layer.borderWidth =
button.layer.cornerRadius =
button.setTitle("I am Abel", forState: UIControlState.Normal)//设置按钮标题
button.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)//设置按钮标题颜色
self.view.addSubview(button)
//为按钮添加阴影
button.layer.shadowOpacity = 0.8
button.layer.shadowColor = UIColor.blackColor().CGColor
button.layer.shadowOffset = CGSize(width: , height: )
运行效果: