Skip to content

Instantly share code, notes, and snippets.

// Taken from the commercial iOS PDF framework http://pspdfkit.com.
// Copyright (c) 2014 Peter Steinberger, PSPDFKit GmbH. All rights reserved.
// Licensed under MIT (http://opensource.org/licenses/MIT)
//
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it.
#import <objc/runtime.h>
#import <objc/message.h>
// Compile-time selector checks.
@PhilCai1993
PhilCai1993 / CALayer_With_ResizableImage.m
Last active October 1, 2017 02:33
CALayer and [UIImage resizableImageWithCapInsets:resizingMode]
static CGRect CGRectCenterRectForResizableImage(UIImage* image) {
return CGRectMake(image.capInsets.left / image.size.width,
image.capInsets.top / image.size.height,
(image.size.width - image.capInsets.right - image.capInsets.left) / image.size.width,
(image.size.height - image.capInsets.bottom - image.capInsets.top) / image.size.height);
}
...