Swift-Add a shaded border to pictures and buttons

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.