Class: SC.AutoResize

Use this mixin to make your view automatically resize based upon its value, title, or other string property. Only works for views that support automatic resizing.

Supporting Automatic Resizing

To support automatic resizing, your view must provide these properties:

Your view may also supply:

NOTE: these properties are not defined in the mixin itself because the supporting view, rather than the user of SC.AutoResize, will be providing the properties, and mixing SC.AutoResize into the view should not override these properties.

Defined in: auto_resize.js

Field Summary

Class Methods

Field Detail

SC.AutoResize.autoFitDiscreteFontSizes Boolean

If NO, the calculated font size may be any size between minFontSize and maxFontSize. If YES, it will only be either minFontSize or maxFontSize.

Default value:
SC.AutoResize.batchResizeId String
If this property is provided, all views that share the same value for this property will be resized as a batch for increased performance.
If shouldAutoFitText is YES, this is the calculated font size.

The maximum font size to use when automatically fitting text. If shouldAutoFitText is set, this must be supplied.

Font size is in pixels.

If provided, will limit the maximum height to this value.
If provided, will limit the maximum width to this value.
SC.AutoResize.measuredSize Rect

The measured size of the view's content (the value of the autoResizeField). This property is observable, and, if used in conjunction with setting shouldAutoResize to NO, allows you to customize the 'sizing' part, using SC.AutoResize purely for its measuring code.


The minimum font size to use when automatically fitting text. If shouldAutoFitText is set, this must be supplied.

Font size is in pixels.


If YES, the view's text will be resized to fit the view. This is applied after any resizing, so will only take affect if shouldAutoResize is off, or a maximum width/height is set.

You also must set a minimum and maximum font size. Any auto resizing will happen at the maximum size, and then the text will be resized as necessary.

SC.AutoResize.shouldAutoResize Boolean

If YES, automatically resizes the view (default). If NO, only measures, setting 'measuredSize' to the measured value (you can bind to measuredSize and update size manually).

Default value:
SC.AutoResize.shouldCacheSizes Boolean

Caches sizes for measured strings. This cache does not have a max size, so should only be used when a view has a limited number of possible values. Multiple views that have the same batchResizeId will share the same cache.

Default value:
SC.AutoResize.shouldMeasureSize Boolean
If NO, prevents SC.AutoResize from doing anything at all.
Default value:
SC.AutoResize.shouldResizeHeight Boolean

Determines if the view's height should be resized on calculation. Default is NO to retain backwards compatibility.

Default value:
SC.AutoResize.shouldResizeWidth Boolean

Determines if the view's width should be resized on calculation.

Default value:

Class Method Detail

applyAttributesToContext(orig, context)
Extends renderSettingsToContext to add font size if shouldAutoFitText is YES.
Fits the text into the frame's size, minus autoResizePadding.
Observes the measured size and actually performs the resize if necessary.
Measures the size of the view.
For internal use during batch resizing.

If we are fitting text, the layer must be measured with its font size set to our maximum font size.

Schedules a measurement to happen later.
Whenever the view resizes, the text fitting must be reevaluated.
Documentation generated by JsDoc Toolkit 2.4.0 on Wed Apr 08 2015 10:02:20 GMT-0600 (CST)