简体   繁体   中英

What does shadowOffset do in iOS exactly?

I couldn't find this info anywhere so asking here.

What does element.layer.shadowOffset = CGSizeMake(2.0, 2.0)] do exactly?

What offset does it indicate with respect to the element?

The shadowOffset value changes the location of the shadow with respect to the element's frame. An offset of (2,2) will put the shadow 2 pixels to the right and 2 pixels down with respect to the element. An offset of (15,45) will put the shadow 15 pixels to the right and 45 pixels down. These can also be negative values if you want the shadow to be to the top or left of the element.

And by pixels I mean units. Based off the original (non-retina) pixel sizes of apple devices.

Layers can have a shadow. The layer's shadow uses several elements: shadowOffset , shadowColor , shadowOpacity , and shadowRadius . Each element changes the respective appearance.

You can offset the shadow differently to change the direction the shadow is cast - how far from the layer and in which direction. shadowColor will obviously change what color the shadow is (in case you don't want to use the default grayish color). The shadowOpacity will adjust how opaque the shadow is. The shadowRadius will adjust how large the shadow is.

shadowOffset takes in a CGSize. So you could for instance set your color for the shadow to green (just to make it visible) then set the offset like so:
element.layer.shadowOffset = CGSizeMake(2.0, 2.0)];
This will set the shadow to appear to the bottom right. The Offset value can be anything you want, the first value in the CGSize is distance left/right (with negative being left, and positive being right), and second value is distance up/down (negative/positive respectively).

ShadowOffset is a CGSize representing how far to offset the shadow from the path. The default value of this property is (0.0, -3.0).

It effectively sets where the light that casts the shadow is. So it controls if the shadow is above / below, left / right. And by how much.

Mmm... the Google tells me that it is listed in Apple's documentation for CALayer : shadowOffset

shadowOffset

The offset (in points) of the layer’s shadow. Animatable.
@property CGSize shadowOffset
Discussion

The default value of this property is (0.0, -3.0).
Availability

    Available in iOS 3.2 and later.

Related Sample Code

    MTAudioProcessingTap Audio Processor

Declared In
CALayer.h

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM