• Stars
    star
    102
  • Rank 335,584 (Top 7 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created almost 11 years ago
  • Updated almost 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Turns static PaintCode or Qwarkee code into a UIView that honors the contentMode property

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

  1. 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.
  2. Set the object's contentMode as desired.
  3. Add the view to a view hierarchy or draw it manually using - (void)drawInFrame:(CGRect)frame.

Subclassing

  1. Create a new class to represent the graphic, and make sure it inherits from MMScalableVectorView.
  2. Implement the following methods:
    1. Paste the Qwarkee/PaintCode drawing code into drawInCurrentContext
    2. Implement originalSize to return a CGSize structure for the native size of the vector graphic.
  3. 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

  1. UIView category with a block-based initializer for one-step creation of vector-backed UIViews.
  2. Improving drawing when UIView’s transform property is used (?)
  3. Unit tests!