Resizing Drawing Methods
By default, all new canvases will generate drawing methods that take two extra arguments: target frame and resizing behavior. The target frame defines the available space into which the canvas should be rendered — typically bounds of the view. Resizing behavior is one of the 4 provided enum values that control how the contents are scaled in the target frame:
-
aspectFit
— fit the target frame while preserving aspect ratio -
aspectFill
— fill the target frame while preserving aspect ratio -
center
— preserve original size and center within target frame -
stretch
— fill target frame ignoring aspect ratio
New canvases have this feature enabled by default. In case the canvas is used as Symbol, it is forced to generate resizing arguments. Otherwise the feature can be turned on and off in canvas settings:
Frames
In case your canvas uses Frame to handle resizing, then other resizing drawing methods are not generated.
Example
Interface of Resizing Method in StyleKit in Objective-C:
+ (void)drawTriangle; + (void)drawTriangleWithFrame: (CGRect)targetFrame resizing: (StyleKitNameResizingBehavior)resizing;
and usage in UIView subclass:
- (void)drawRect: (CGRect)rect { [StyleKit drawTriangleWithFrame: self.bounds resizing: StyleKitResizingBehaviorAspectFit]; }