Recently busy, want to do a lot of things, can do out of only one part, I think maybe I did not plan and rule caused, I need to persist, today wrote a swift2.0 to the button or image to add shadow effect, as a note it:-)
Swift Code:
Let Image1 = Uiimageview (Frame:cgrectmake ( -, -, self.view.frame.width- -, the)) Image1.image= UIImage (named:"sea.jpg") Self.view.addSubview (image1)//Add a shadow to a pictureImage1.layer.shadowOpacity =0.8//Set Shadow TransparencyImage1.layer.shadowColor =Uicolor.blackcolor (). Cgcolor Image1.layer.shadowOffset= Cgsize (width:2, Height:2)//Set the shadow offset
Let Image2= Uiimageview (Image:uiimage (named:"Wenzi")) Image2.frame= CGRectMake ( -, the, self.view.frame.width- -, $) Self.view.addSubview (image2)//Add a shadow to a picture (transparent background)Image2.layer.shadowOpacity =0.8Image2.layer.shadowColor=Uicolor.blackcolor (). Cgcolor Image2.layer.shadowOffset= Cgsize (width:6, Height:6) Image2.layer.shadowRadius=1Let button= UIButton (Frame:cgrectmake ( -, -, $, $)) Button.backgroundcolor= Uicolor (red:0.02, Green:0.48, Blue:1, Alpha:1) //Set rounded cornersButton.layer.borderColor =Uicolor.whitecolor (). Cgcolor Button.layer.borderWidth=2Button.layer.cornerRadius=TenButton.settitle ("I am Abel", ForState:UIControlState.Normal)//Set Button captionButton.settitlecolor (Uicolor.whitecolor (), ForState:UIControlState.Normal)//Set Button caption Colorself.view.addSubview (Button)//Add a shadow to a buttonButton.layer.shadowOpacity =0.8Button.layer.shadowColor=Uicolor.blackcolor (). Cgcolor Button.layer.shadowOffset= Cgsize (width:1, Height:1)
Operating effect:
Swift-Add a shaded border to pictures and buttons