Latest 0.1.0
Homepage https://github.com/mruegenberg/uiview-hierarchical-drawing
License MIT
Platforms ios 5.0, requires ARC
Frameworks UIKit
Authors

uiview-hierarchical-drawing

This is a category on UIView, which directly calls drawRect hierarchically. This allows you to use any UIGraphicsContext, and in particular PDF contexts.
The benefit: Beautiful, crystal clear rendering.

Usage

#import "UIView+HierarchicalDrawing.h"

CGSize pageSize = CGSizeMake(842.4,597.6);
NSMutableData *pdfData = [NSMutableData data];
UIGraphicsBeginPDFContextToData(pdfData, CGRectMake(0, 0, pageSize.width, pageSize.height), documentInfoDict);
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
CGContextSetInterpolationQuality(pdfContext, kCGInterpolationHigh);

[theView drawHierarchy];

UIGraphicsEndPDFContext();
// use pdfData

Example

Below are two examples of rendering into a PDF context. One uses UIView+HierarchicalDrawing with drawHierarchy, the other -[CALayer renderInContext:] with a contentScaleFactor of 2 on the view.

  • Using UIView+HierarchicalDrawing:
    hierarchical

  • renderInContext:
    renderInContext

Known issues

There are some possible problems with custom patterns as view backgrounds.

License

MIT. See LICENSE.

Latest podspec

{
    "name": "UIView+HierarchicalDrawing",
    "version": "0.1.0",
    "summary": "Draw UIView hierarchy in any UIGraphicsContext manually, for crisp rendering of PDFs from views in iOS",
    "description": "                   This library traverses a UIView hierarchy and calls drawRect directly, with various tweaks along the way.n                   n                   The upside is that drawing calls are directly passed to the current UIGraphicsContext, which allows e.gn                   generation of high-quality PDFs directly from your UIView drawing code.n                   n                   Please see the README for an example.n",
    "homepage": "https://github.com/mruegenberg/uiview-hierarchical-drawing",
    "screenshots": "https://raw.github.com/mruegenberg/uiview-hierarchical-drawing/gh-pages/screenshot.png",
    "license": "MIT",
    "authors": {
        "Marcel Ruegenberg": "[email protected]"
    },
    "platforms": {
        "ios": "5.0"
    },
    "source": {
        "git": "https://github.com/mruegenberg/uiview-hierarchical-drawing.git",
        "tag": "0.1.0"
    },
    "source_files": "UIView+HierarchicalDrawing.{h,m}",
    "public_header_files": "UIView+HierarchicalDrawing.h",
    "frameworks": "UIKit",
    "requires_arc": true
}

Pin It on Pinterest

Share This