MMScalableVectorView
Turns static PaintCode or Qwarkee code into a UIView that honors its contentMode property.
Before |
After |
Installation
CocoaPods
pod "MMScalableVectorView"
Manually
Just import MMScalableVectorView.m & .h into your project directly.
Requirements
- iOS 4.x or higher
- CoreGraphics framework
- ARC
Usage
Using MMScalableVectorView Directly
- 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
.
Subclassing
- 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.
Demo
Run pod install
inside the Demo folder, then load the Demo workspace & run!
Future Improvements
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!