UIView(DTFoundation) Category Reference
Declared in | UIView+DTFoundation.h |
Instance Methods
addShadowWithColor:alpha:radius:offset:
Adds a layer-based shadow to the receiver.
- (void)addShadowWithColor:(UIColor *)color alpha:(CGFloat)alpha radius:(CGFloat)radius offset:(CGSize)offset
Parameters
- color
The shadow color. Can be
nil
for default black.
- alpha
The alpha value of the shadow.
- radius
The amount that the shadow is blurred.
- offset
The offset of the shadow
Discussion
The advantage of using this method is that you do not need to import the QuartzCore headers just for adding the shadow. Layer-based shadows are properly combined for views that are on the same superview. This does not add a shadow path, you should call updateShadowPathToBounds whenever the receiver’s bounds change and also after setting the initial frame. @warn Disables clipping to bounds because this would also clip off the shadow.
Declared In
UIView+DTFoundation.h
setRoundedCornersWithRadius:width:color:
Sets the corner attributes of the receiver’s layer.
- (void)setRoundedCornersWithRadius:(CGFloat)radius width:(CGFloat)width color:(UIColor *)color
Parameters
- radius
The corner radius.
- width
The width of the border line.
- color
The color to be used for the border line. Can be
nil
to leave it unchanged.
Discussion
The advantage of using this method is that you do not need to import the QuartzCore headers just for setting the corners.
Declared In
UIView+DTFoundation.h
snapshotImage
Creates a snapshot of the receiver.
- (UIImage *)snapshotImage
Return Value
Returns a bitmap image with the same contents and dimensions as the receiver.
Declared In
UIView+DTFoundation.h
updateShadowPathToBounds:withDuration:
sets the shadow path to fit the receiver’s bounds.
- (void)updateShadowPathToBounds:(CGRect)bounds withDuration:(NSTimeInterval)duration
Parameters
- bounds
The new bounds of the shadow path
- duration
The animation duration. Specify a duration of 0 to not do an animation
Discussion
This should be called whenever the receiver’s bounds change, or else the shadow detaches.
@warn Since this a CALayer property it needs to be explicitly animated, for example in the willRotate … method of a UIViewController
.
Declared In
UIView+DTFoundation.h