Skip to content

UIView ​

UIView represents a rectangular area on the screen, called a view. A view does three things: it displays content (a background color, plus text or images that subclasses provide), it contains other views, and it receives touches. Buttons, text, images, and scrolling areas are all subclasses of UIView, and the members on this page work on every view.

Views form a tree. Each view has at most one superview and any number of subviews, and the root of the tree is a window (UIWindow). A view appears on screen only after it is connected to a window. A view that isn't connected to a window can still be created, have its properties set, and get subviews; it just isn't visible.

A view's position and size aren't worked out automatically. The app's code supplies them: either by writing a rectangle directly (frame), or by writing constraints and letting the system compute it. Lengths are in points (pt); one point covers 2 × 2 or 3 × 3 pixels on screen. See Units.

Appearance is set through properties such as backgroundColor and alpha. Corner radius, borders, and shadows are on the view's layer, view.layer. See CALayer.

Inheritance: EventTarget → NSObject → UIResponder → UIView

Subclasses of UIView: UIWindow, UILabel, UIImageView, UIControl (UIButton, UITextField), UIScrollView, UIStackView.

For creating, positioning, hiding, and removing views, see the guide Placing views on screen. For animation, see Animating views. For constraints, see Laying out with constraints.

Constructor ​

UIView()

Creates a view. A new view's frame is (0, 0, 0, 0), with no background color and no superview. UIView can't be subclassed.

Static methods ​

MethodDescription
UIView.animateWithDuration()Changes view properties with animation. Returns a Promise that fulfills when the animation ends
UIView.performWithoutAnimation()Runs a block of code whose changes aren't animated

Instance properties ​

Also inherits isFirstResponder and canBecomeFirstResponder from UIResponder. See Text fields and the keyboard.

Position and size. All in pt:

PropertyDescription
framePosition and size in the superview's coordinate system
boundsThe rectangle in the view's own coordinate system
centerPosition of the center point in the superview's coordinate system
transform2D affine transform
anchorPointThe point the transform is applied around, as a ratio
safeAreaInsets read-onlyDistances from the four edges of the safe area to the four edges of the view
directionalLayoutMarginsLayout margins, with left and right determined by text direction
layoutMarginsThe same layout margins, with fixed left and right
insetsLayoutMarginsFromSafeAreaWhether the safe area is added to the layout margins
preservesSuperviewLayoutMarginsWhether to use the superview's layout margins when they are larger
intrinsicContentSize read-onlyThe intrinsic size computed from the content
alignmentRectInsets read-onlyHow far the alignment rectangle is inset from frame
contentScaleFactorHow many pixels 1 pt covers
autoresizingMaskHow a view positioned by frame follows when the superview's size changes
autoresizesSubviewsWhether subviews are adjusted when the size changes

View hierarchy:

PropertyDescription
superview read-onlyThe superview
subviews read-onlySubviews, in drawing order
window read-onlyThe window the view is in
tagAn integer you assign yourself

Appearance:

PropertyDescription
backgroundColorBackground color
alphaOpacity, 0 to 1
isHiddenWhether the view is hidden
clipsToBoundsWhether subviews that extend outside are clipped
isOpaqueA drawing hint for the system: whether the content is fully opaque
contentModeHow content is placed when its size differs from the view's
layer read-onlyThe view's layer: corner radius, borders, shadows
maskViewMask view
tintColorTint color
tintAdjustmentModeWhether the tint color is shown normally or dimmed
clearsContextBeforeDrawingWhether existing content is cleared before redrawing

Traits and writing direction:

PropertyDescription
traitCollection read-onlyTraits of the environment: light or dark, screen scale, text size
overrideUserInterfaceStyleForces light or dark
semanticContentAttributeWhether to flip left and right in right-to-left languages
effectiveUserInterfaceLayoutDirection read-onlyThe writing direction actually in use
appliedContentSizeCategoryLimitsDescription read-onlyFor debugging: which text sizes are limited

Touch and focus:

PropertyDescription
isUserInteractionEnabledWhether the view receives touches
isMultipleTouchEnabledWhether the view receives multiple fingers
isExclusiveTouchWhether the view takes touches exclusively while touched
gestureRecognizers read-onlyThe gesture recognizers on the view
canBecomeFocused read-onlyWhether the view can get focus
isFocused read-onlyWhether the view has focus right now
focusGroupIdentifierName of the focus group

Constraints (Auto Layout). Anchors are used to build constraints; see NSLayoutAnchor:

PropertyDescription
translatesAutoresizingMaskIntoConstraintsPositioned by frame or by constraints. Must be false on views that use constraints
leadingAnchor read-onlyLeading edge
trailingAnchor read-onlyTrailing edge
leftAnchor read-onlyLeft edge
rightAnchor read-onlyRight edge
centerXAnchor read-onlyHorizontal center line
topAnchor read-onlyTop edge
bottomAnchor read-onlyBottom edge
centerYAnchor read-onlyVertical center line
firstBaselineAnchor read-onlyBaseline of the first line of text
lastBaselineAnchor read-onlyBaseline of the last line of text
widthAnchor read-onlyWidth
heightAnchor read-onlyHeight
safeAreaLayoutGuide read-onlyThe layout guide that represents the safe area
layoutMarginsGuide read-onlyThe area inset by the layout margins
readableContentGuide read-onlyA width range suited to reading long text
keyboardLayoutGuide read-onlyThe area the keyboard occupies
layoutGuides read-onlyLayout guides you added
constraints read-onlyConstraints stored on this view
hasAmbiguousLayout read-onlyWhether there are enough constraints
viewForFirstBaselineLayout read-onlyWhich view the first baseline comes from
viewForLastBaselineLayout read-onlyWhich view the last baseline comes from

Accessibility and state restoration. VoiceOver is the screen reader built into iOS; for how to make it read your interface correctly, see the guide Making VoiceOver read your interface correctly:

PropertyDescription
isAccessibilityElementWhether VoiceOver treats it as one element to stop on and read
accessibilityLabelThe name VoiceOver reads: what it is
accessibilityHintThe hint VoiceOver reads after the name: what operating it does
accessibilityValueThe current value VoiceOver reads
accessibilityTraitsWhat kind of thing it is and what state it is in: button, heading, selected, and so on
accessibilityIdentifierAn identifier automated UI tests use to find elements; VoiceOver doesn't read it
accessibilityElementsHiddenWhether VoiceOver skips all the elements inside it
accessibilityViewIsModalWhether VoiceOver stays inside it and skips its siblings. Used for overlays
shouldGroupAccessibilityChildrenWhether VoiceOver reads the elements inside it as one group, in a row
accessibilityIgnoresInvertColorsWhether the view stays as-is under Smart Invert
showsLargeContentViewerWhether an enlarged version is shown on long press
largeContentTitleText shown in the large content viewer
largeContentImageImage shown in the large content viewer
scalesLargeContentImageWhether the image is scaled up in the large content viewer
largeContentImageInsetsInsets around the image in the large content viewer
restorationIdentifierThe name the system uses to recognize the view when restoring interface state

Instance methods ​

Also inherits becomeFirstResponder() and resignFirstResponder() from UIResponder. See Text fields and the keyboard.

View hierarchy:

MethodDescription
addSubview()Adds a subview on top
insertSubview()Adds a subview at a given position
removeFromSuperview()Removes the view from its superview
bringSubviewToFront()Moves a subview to the top
sendSubviewToBack()Moves a subview to the bottom
exchangeSubviewAtIndex()Swaps the positions of two subviews
isDescendantOfView()Whether the view is a descendant of another view
viewWithTag()Finds a view by tag

Geometry:

MethodDescription
sizeThatFits()How large the view must be to show all its content
sizeToFit()Resizes the view to just fit its content
convertPoint()Converts a point to another view's coordinate system
convertRect()Converts a rectangle to another view's coordinate system
hitTest()The topmost view at a location that can receive touches
alignmentRectForFrame()Converts a frame to an alignment rectangle
frameForAlignmentRect()Converts an alignment rectangle to a frame
effectiveRadiusForCorner()The actual corner radius of a given corner

Gesture recognizers:

MethodDescription
addGestureRecognizer()Adds a gesture recognizer
removeGestureRecognizer()Removes a gesture recognizer

Layout, redrawing, and updates. The system doesn't lay out again immediately after every property change; it sets a flag and handles everything together later. In everyday code you only need layoutIfNeeded():

MethodDescription
layoutIfNeeded()Completes any pending layout immediately. Call it when you need to read frame right after activating constraints
setNeedsLayout()Marks the view as needing layout
setNeedsDisplay()Marks the view as needing redrawing
setNeedsDisplayInRect()Marks a rectangle as needing redrawing
setNeedsUpdateConstraints()Marks the constraints as needing an update
updateConstraintsIfNeeded()Completes any pending constraint update immediately
needsUpdateConstraints()Whether a constraint update is pending
setNeedsUpdateProperties()Marks the properties as needing an update
updatePropertiesIfNeeded()Completes any pending property update immediately
updateTraitsIfNeeded()Completes any pending trait update immediately

Constraints (Auto Layout):

MethodDescription
addLayoutGuide()Adds a layout guide
removeLayoutGuide()Removes a layout guide
contentHuggingPriorityForAxis()Reads the "resist being stretched" priority
setContentHuggingPriority()Sets the "resist being stretched" priority
contentCompressionResistancePriorityForAxis()Reads the "resist being squeezed" priority
setContentCompressionResistancePriority()Sets the "resist being squeezed" priority
invalidateIntrinsicContentSize()Tells the system the intrinsic size has changed
systemLayoutSizeFittingSize()Computes how large the view should be from its constraints
constraintsAffectingLayoutForAxis()The constraints that actually affect this view
exerciseAmbiguityInLayout()When constraints are insufficient, switches once between the possible results

Snapshots and the keyboard:

MethodDescription
snapshotViewAfterScreenUpdates()Takes a snapshot and returns a new view that displays it
resizableSnapshotViewFromRect()Takes a stretchable snapshot of a region
endEditing()Makes the text field being edited lose focus and dismisses the keyboard

Events ​

EventWhen it fires
traitchangeWhen traits (light or dark, text size, and so on) change

This is the only event UIView itself fires. Touches don't produce UIView events. To respond to touches, use a gesture recognizer or a subclass of UIControl.

Apart from traitchange, none of the properties on this page have change notifications: there is no event when the position, size, or superview changes.

You can listen for and dispatch events with custom names on a plain UIView, the same as on a plain EventTarget. The same goes for subclasses with their own set of events (such as UIControl): any name the system doesn't fire is treated as a custom event.

Concepts ​

frame, bounds, and center ​

All three properties describe a view's position and size. They differ in which coordinate system they refer to.

PropertyCoordinate systemWhat it is
frameThe superview'sThe rectangle the view occupies in its superview
boundsThe view's ownThe view's own rectangle. The top-left corner is usually (0, 0), and the width and height match frame
centerThe superview'sThe position of the view's center point

The origin is at the top-left corner; x increases to the right and y increases downward.

A subview's frame is relative to its superview's top-left corner, not to the screen. When the superview moves, the subview moves with it, and the subview's frame doesn't change.

Choose by what you want to do:

TaskUseWhy
Put a view at a position in its superviewWrite its frameframe uses the superview's coordinate system
Find out how large a view is, or make a subview fill itRead its boundsSubview coordinates are relative to its top-left corner, and bounds is exactly the rectangle in that coordinate system. Reading the superview's frame brings in the superview's own position
Move without resizingWrite centerNo need to repeat the width and height
The view has a transformUse bounds and center, not frameSee Transforms and frame

The three properties are the same data: write one, and the other two read back changed accordingly. For a view positioned by constraints, all three are read-only in practice; see Two ways to position views.

View hierarchy and stacking order ​

Views form a tree. Each view has at most one superview (superview) and any number of subviews (subviews).

  • The order of subviews is the drawing order: later views are drawn on top. Stacking order is determined only by this order; there is no separate z-index value. For two views under different superviews, which one is on top is determined by the order of their respective ancestors within their common superview.
  • A view can have only one superview at a time. Adding a view that already has a superview to another superview removes it from the original one; it doesn't appear in two places. Not verified in the simulator.
  • The root of the tree is a window (UIWindow). A view is displayed only after it is added under a window; its window property then has a value. Otherwise it is null.
  • A view controller (UIViewController) comes with a root view, page.view, and all of the view controller's content is added under it.

The view hierarchy can't contain cycles. Adding a view as its own subview throws TypeError, the hierarchy stays unchanged, and the view remains usable afterward:

js
const lone = new UIView();
try {
  lone.addSubview(lone);
} catch (err) {
  console.log(String(err));
}
console.log(lone.subviews.length);

Effect: The console prints TypeError: addSubview: raised NSInvalidArgumentException: Can't add self as subview, then 0.

What happens when you add a view to one of its own descendants (for example dot.addSubview(card), where dot is a subview of card) is not verified in the simulator. You can check first with isDescendantOfView().

Once a view is added to the hierarchy, its superview keeps it alive, so you don't need to hold it in a variable. For whether it is collected after removal, see Who keeps a view alive.

Two ways to position views ​

ApproachHowCharacteristics
Write frame directlyview.frame = new CGRect(…)Position and size are fixed numbers. When the superview's size changes, code has to assign them again
Constraints (Auto Layout)NSLayoutConstraint.activateConstraints([…])Describe relationships between views; the system computes frame and recomputes it when sizes change

Constraints are recommended; see Recommended approach in the guide for why.

Use only one approach per view:

  • For a view that uses constraints, first set translatesAutoresizingMaskIntoConstraints = false. This property defaults to true, meaning "position by frame". If you don't change it, the constraints the system generates from frame conflict with the constraints your code writes, and the symptom is that the constraints are correct but the position doesn't change. The system prints nothing to the console when this conflict happens.
  • For a view that uses constraints, you can read frame, but don't write it. Writing doesn't throw, but on the next layout pass the system overwrites it with the result of the constraints. To change the position, change a constraint's constant or switch to a different set of constraints. "The written frame gets overwritten" is not verified in the simulator.
  • The view controller's root view page.view and windows are positioned by the system. Don't change this property on them, and don't write their frame.

The two approaches can be mixed in the same tree: a superview uses constraints while one of its subviews uses frame. The subview's frame is relative to the superview's top-left corner, and when constraints move the superview, the subview moves with it.

Constraints use two kinds of objects:

  • Anchor: represents one edge, center line, or the width or height of a view, such as view.leadingAnchor. A constraint describes a relationship between two anchors.
  • Layout guide: an invisible rectangle used only for alignment. view.safeAreaLayoutGuide is the one that represents the safe area.

See NSLayoutConstraint and the guide Laying out with constraints.

Safe area ​

The safe area is the part of a view that isn't covered by the notch, the status bar, the screen's rounded corners, or the home indicator.

Each view has its own safe area, computed over that view's extent: a view touching the top of the screen has a strip of safe area inset at its top, while a view entirely in the middle of the screen has 0 pt on all four sides.

There are two ways to read it:

ApproachWhere to use it
view.safeAreaInsetsWhen positioning by frame. Four numbers, in pt
view.safeAreaLayoutGuideWhen positioning by constraints. Align directly to its anchors

safeAreaLayoutGuide is recommended. safeAreaInsets reads 0 pt before the view is shown on screen, so reading it too early gives the wrong values; constraints aligned to safeAreaLayoutGuide don't have this problem. There is no event when the safe area changes. Constraints are recomputed automatically, but code that reads the numbers has to read them again itself.

Background colors and background images usually fill the whole screen, while text and buttons go inside the safe area.

Layout margins ​

Each view has a set of layout margins, which say how far content should be from the view's four edges. There are four things to know about them:

  • They don't inset subviews automatically. Only two things use them: constraints aligned to layoutMarginsGuide, and a UIStackView with isLayoutMarginsRelativeArrangement turned on. Subviews positioned by frame aren't affected.
  • The default isn't 0. A new view has 8 pt on each side.
  • When a view extends outside the safe area, the system adds the safe area to the layout margins. If you write 16 pt and the top safe area is 68 pt, the top margin reads back as 84 pt. To get exactly what you write, set insetsLayoutMarginsFromSafeArea to false.
  • A view controller's root view has a system-defined minimum margin. If you write layout margins on page.view smaller than the minimum, they read back as the minimum. Not verified in the simulator.

There are two layout margin properties. They are two ways of reading the same data; write one and the other changes accordingly:

PropertyTypeFour fieldsHow left and right work
directionalLayoutMarginsNSDirectionalEdgeInsetstop, leading, bottom, trailingleading is the side where text starts and trailing is the side where text ends. In English and Chinese leading is on the left; in right-to-left languages such as Arabic it is on the right
layoutMarginsUIEdgeInsetstop, left, bottom, rightFixed left and right

Prefer directionalLayoutMargins: the interface then swaps left and right automatically in right-to-left languages.

js
const box = new UIView();
box.directionalLayoutMargins = new NSDirectionalEdgeInsets(1, 2, 3, 4);
String(box.layoutMargins);              // 'UIEdgeInsets(1, 2, 3, 4)' when the language is left-to-right

box.layoutMargins = { top: 5, left: 6, bottom: 7, right: 8 };
String(box.directionalLayoutMargins);   // 'NSDirectionalEdgeInsets(5, 6, 7, 8)'

Transforms and frame ​

transform is a 2D affine transform: translation, scaling, rotation, and combinations of them. The transform uses the view's center as its origin and changes only how the view is drawn, not bounds or center.

When transform isn't the identity matrix, frame reads back as the bounding rectangle of the transformed shape, no longer the view's original rectangle:

js
const box = new UIView();
box.frame = new CGRect(24, 304, 40, 40);
box.transform = CGAffineTransform.scale(1.2)
  .concat(CGAffineTransform.rotation(Math.PI / 6));

box.bounds.width;    // 40, unchanged
box.center.x;        // 44, unchanged
box.frame.width;     // 65.57, equal to 40 × (|a| + |c|), where a and c are fields of the transform matrix

So while a transform is applied, use center to change the position and bounds to change the size, and don't read or write frame. After transform is set back to CGAffineTransform.identity, frame returns to 40 × 40.

For constructing transforms, see CGAffineTransform.

Structs are read-only values ​

The types of frame, bounds, center, transform, safeAreaInsets, layoutMargins, and directionalLayoutMargins are structs such as CGRect and CGPoint. A struct is a value, not a reference to the view:

  • Each read of the property returns a new object.
  • Fields can't be changed. Writing view.frame.x = 10 throws TypeError: x is read-only: structs are values, assign a whole new one instead.
  • To change it, assign a whole new value to the property. You can assign a new CGRect(…) or a plain object with all fields present.

See Structs.

What happens on errors ​

The result depends on where the mistake is.

MistakeResult
A numeric property gets another type (view.alpha = '0.5')Converted with Number(): '0.5' becomes 0.5, null becomes 0. If it doesn't convert to a finite number, throws TypeError and the value stays unchanged
A boolean property gets another type (view.isHidden = 'false')Converted with Boolean(). Every non-empty string is true, so 'false' becomes true
Something other than a view is passed where a view is expected (view.addSubview(5))Throws TypeError; the view hierarchy is unchanged. No conversion happens
An invalid color (view.backgroundColor = '#GGG')Doesn't throw. The console prints a warning and the color keeps its previous value
An invalid enum property value (view.contentMode = 'cover')Doesn't throw. The console prints a warning listing all valid values, and the property keeps its previous value
An invalid enum in a method argument (view.setContentHuggingPriority('defaultHigh', { forAxis: 'diagonal' }))Throws TypeError; the message lists all valid values
Writing a read-only property (view.superview = null)Throws TypeError
A misspelled property name (view.backgroundColour = 'red')No error; the view doesn't change. Type checking catches it
Adding a view as its own subviewThrows TypeError; the view hierarchy is unchanged
SituationError
Reading or writing a property, or calling a method, on a window not yet bound to a scene (new UIWindow() called without an argument, and windowScene not yet assigned)TypeError: frame: this object is not connected to a scene yet, so no native object exists, starting with the property or method name
Calling on an object not created by the constructor (for example Object.create(UIView.prototype))TypeError: frame: Illegal invocation
A parameter that expects a native object gets something elseTypeError: addSubview needs a UIView, starting with the method name and ending with the required class. For parameters that can be null, it ends with an extra or null
A numeric parameter or property doesn't convert to a finite numberTypeError: alpha must be a finite number, got "abc", starting with the property or parameter name
An enum in a method argument has an unrecognized valueTypeError: forAxis has no value "diagonal"; expected one of: …

On error, the property being written keeps its previous value and the view hierarchy is unchanged. All of these errors can be caught with try / catch.

Writing an unrecognized value to an enum property (contentMode, overrideUserInterfaceStyle) isn't an error: it doesn't throw, the property keeps its previous value, and the console prints a warning [Nacre] contentMode has no value "cover"; expected one of: …, ignored.

Each member's exact error messages are on its member page. For the various "no native object" errors, see Native classes.

Note: A misspelled property name doesn't throw. view.backgroundColour = 'red' just adds an ordinary property to the JS object, and the view doesn't change. Type checking catches this kind of mistake: it reports an error with the hint Did you mean 'backgroundColor'?.

Examples ​

A small square inside a rectangle ​

The code below starts from a blank app, puts an indigo rectangle on the screen, and puts a small orange square inside the rectangle.

js
application.addEventListener('sceneconnect', (e) => {
  // Create the window and view controller. Every app needs these lines
  const win = new UIWindow(e.scene);
  const page = new UIViewController();
  page.view.backgroundColor = 'systemBackground';
  win.rootViewController = page;
  win.makeKeyAndVisible();

  // 1. Create the view
  const card = new UIView();

  // 2. Set position and size: top-left corner at (40, 120), 200 wide, 120 tall
  card.frame = new CGRect(40, 120, 200, 120);

  // 3. Set the background color
  card.backgroundColor = 'systemIndigo';

  // 4. Put it on the view controller. page.view is the view controller's built-in root view
  page.view.addSubview(card);

  // 5. Put another subview inside card. Its coordinates are relative to card's top-left corner
  const dot = new UIView();
  dot.frame = new CGRect(16, 16, 40, 40);
  dot.backgroundColor = 'systemOrange';
  card.addSubview(dot);

  // 6. Convert dot's top-left corner to the view controller's coordinates
  const p = dot.convertPoint(new CGPoint(0, 0), { toView: page.view });
  console.log(p.x, p.y);
});

Effect

  • An indigo rectangle appears on screen, 200 pt wide and 120 pt tall, with its left edge 40 pt from the left of the screen and its top edge 120 pt from the top of the screen.
  • Inside the rectangle's top-left corner is a 40 × 40 pt orange square, 16 pt from the rectangle's left and top edges.
  • The console prints 56 176, that is, 40 + 16 and 120 + 16.

This code hasn't been run as a whole in the simulator. Every API it uses has been run in the acceptance tests.

The four basic steps are: create, give it a position and size, set its appearance, and add it to a superview. After the callback ends, the variables card and dot no longer exist, but both views stay on screen: they are in the view hierarchy, kept alive by their superviews. For more patterns, see the guide Placing views on screen.

Corresponding iOS API ​

If you are reading Apple's documentation or iOS sample code, use this table to convert to JS.

ObjCJS
[[UIView alloc] init]new UIView()
[[UIView alloc] initWithFrame:rect]new UIView(), then assign frame
view.frame = CGRectMake(40, 120, 200, 120)view.frame = new CGRect(40, 120, 200, 120)
view.center = CGPointMake(100, 100)view.center = new CGPoint(100, 100)
view.transform = CGAffineTransformMakeRotation(a)view.transform = CGAffineTransform.rotation(a)
view.backgroundColor = UIColor.systemIndigoColorview.backgroundColor = 'systemIndigo'
[view addSubview:box]view.addSubview(box)
[view insertSubview:box atIndex:0]view.insertSubview(box, { atIndex: 0 })
[view insertSubview:box belowSubview:other]view.insertSubview(box, { belowSubview: other })
[view convertPoint:p toView:other]view.convertPoint(p, { toView: other })
[view convertRect:r fromView:other]view.convertRect(r, { fromView: other })
view.directionalLayoutMargins = NSDirectionalEdgeInsetsMake(8, 16, 8, 16)view.directionalLayoutMargins = new NSDirectionalEdgeInsets(8, 16, 8, 16)
view.layoutMargins = UIEdgeInsetsMake(8, 16, 8, 16)view.layoutMargins = new UIEdgeInsets(8, 16, 8, 16)
view.insetsLayoutMarginsFromSafeArea = NOview.insetsLayoutMarginsFromSafeArea = false
[view sizeThatFits:CGSizeMake(300, 999)]view.sizeThatFits(new CGSize(300, 999))
[view hitTest:p withEvent:nil]view.hitTest(p)
[view endEditing:YES]view.endEditing(true)
[view addGestureRecognizer:tap]view.addGestureRecognizer(tap)
[UIView animateWithDuration:0.3 animations:^{ view.alpha = 0; }]UIView.animateWithDuration(0.3, { animations() { view.alpha = 0; } })
[UIView animateWithDuration:0.3 animations:^{ … } completion:^(BOOL finished) { … }]const finished = await UIView.animateWithDuration(0.3, { animations() { … } })
[UIView animateWithDuration:0.3 delay:0.1 options:UIViewAnimationOptionCurveEaseOut animations:^{ … } completion:nil]UIView.animateWithDuration(0.3, { delay: 0.1, options: ['curveEaseOut'], animations() { … } })
[UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:0.6 initialSpringVelocity:0 options:0 animations:^{ … } completion:nil]UIView.animateWithDuration(0.5, { usingSpringWithDamping: 0.6, initialSpringVelocity: 0, animations() { … } })
[UIView performWithoutAnimation:^{ … }]UIView.performWithoutAnimation(() => { … })
view.hidden = YESview.isHidden = true
view.opaque = NOview.isOpaque = false
view.userInteractionEnabled = NOview.isUserInteractionEnabled = false
view.contentMode = UIViewContentModeScaleAspectFitview.contentMode = 'scaleAspectFit'
[view setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal]view.setContentHuggingPriority('defaultLow', { forAxis: 'horizontal' })
view.accessibilityTraits = UIAccessibilityTraitButton | UIAccessibilityTraitSelectedview.accessibilityTraits = ['button', 'selected']

There are three rules:

  • For boolean properties declared in ObjC as getter=isXxx, JS reads and writes them under the name isXxx, such as isHidden.
  • For a multi-part method name, the first part is the JS method name and the remaining parts are keys of the options object.
  • The four ObjC animateWithDuration:… methods are a single method in JS. The completion: parameter is replaced by the returned Promise.

See also ​