Swift UI special training Imagevi picture Border Shadow

Source: Internet
Author: User

ImageView is a component we often use, but we find that there is no design for picture borders in the property editor of storyboard. Add a normal picture to the view, the effect is this:

Can see, the white background of the dark picture, the effect is always a little abrupt, we want to add a shadow border to transition a piece and background, open the picture belongs to the controller code, the class is displayed in the picture named image, now to set its border. Enter the following code in Viewdidload:

Image.layer.backgroundColor = Uicolor.orangecolor (). Cgcolor        Image.layer.shadowColor = Uicolor.blackcolor (). Cgcolor        image.layer.shadowOffset = cgsizemake (0, 0)        image.layer.shadowOpacity = 0.5        Image.layer.shadowRadius = 10.0
Using the layer attribute, command to look at the source of the layer:

var layer:calayer {Get}//Returns view ' s layer. Would always return a non-nil value. View is layer ' s delegate

Can see it is a calyer type, Calyer type has a lot of methods, interested small partners can click to see.

Note that the property of layer backgroundcolor is not the type of uicolor that we commonly use, it is a cgcolor type, and if you use a strong-turn statement it won't work:

Image.layer.backgroundColor = Uicolor.orangecolor () as Cgcolor

or a

Image.layer.backgroundColor = (Cgcolor) uicolor.orangecolor ()

is not feasible, the possible way is the above code, in the following add one. Cgcolor.

Now run for a look at the effect:

Now the border shadow has been added, is not very flashy?

Swift UI special training Imagevi picture Border Shadow

Related Article

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.