Turns static PaintCode or Qwarkee code into a UIView that honors its contentMode property.
Before |
After |
pod "MMScalableVectorView"
Just import MMScalableVectorView.m & .h into your project directly.
- iOS 4.x or higher
- CoreGraphics framework
- ARC
- Use
- (id)initWithFrame:(CGRect)frame drawingBlock:(void (^)(void))drawingBlock originalSize:(CGSize)originalSize
to create a new instance of MMScalableVectorView, providing the vector drawing block and original size. - Set the object's
contentMode
as desired. - Add the view to a view hierarchy or draw it manually using
- (void)drawInFrame:(CGRect)frame
.
- Create a new class to represent the graphic, and make sure it inherits from MMScalableVectorView.
- Implement the following methods:
- Paste the Qwarkee/PaintCode drawing code into
drawInCurrentContext
- Implement
originalSize
to return aCGSize
structure for the native size of the vector graphic.
- Paste the Qwarkee/PaintCode drawing code into
- Use the newly created class as a normal UIView, setting the
contentMode
property as desired before the view is drawn. This can be done in Interface Builder or programatically.
Run pod install
inside the Demo folder, then load the Demo workspace & run!
UIView category with a block-based initializer for one-step creation of vector-backed UIViews.- Improving drawing when UIView’s transform property is used (?)
- Unit tests!