UIView: resizableSnapshotViewFromRect() method
The resizableSnapshotViewFromRect() method takes a snapshot of a rectangle within the view and returns a resizable snapshot view: when it stretches, the border given by withCapInsets stays fixed and only the middle stretches.
Syntax
resizableSnapshotViewFromRect(rect, { afterScreenUpdates, withCapInsets })Parameters
rect
The rectangle to capture, a CGRect or { x, y, width, height }, in the view's own coordinate system, in pt.
options.afterScreenUpdates
A boolean. Required. Same meaning as in snapshotViewAfterScreenUpdates().
options.withCapInsets
A UIEdgeInsets or a plain object with all four fields. Required. The widths around the edges that stay fixed when stretching, in pt.
Return value
A new UIView, or null if the snapshot can't be taken.
Exceptions
TypeError
afterScreenUpdatesis missing:resizableSnapshotViewFromRect needs { afterScreenUpdates }.withCapInsetsis missing:resizableSnapshotViewFromRect needs { withCapInsets }.rectorwithCapInsetsisn't an object or is missing fields: same rules as for structs.
Description
This method was added later and hasn't been called in the simulator. Its effect is not verified in the simulator.
Examples
const card = new UIView();
card.frame = new CGRect(0, 0, 200, 120);
const copy = card.resizableSnapshotViewFromRect(card.bounds, {
afterScreenUpdates: false,
withCapInsets: new UIEdgeInsets(12, 12, 12, 12),
});Effect: When copy stretches, the 12 pt border around the edges stays fixed. Not verified in the simulator.
Corresponding iOS API
-[UIView resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets:]. The last two parts become options keys.