Skip to content

NSDirectionalEdgeInsets ​

NSDirectionalEdgeInsets represents how far each of the four edges is inset, with left and right distinguished by text direction: top, leading, bottom, trailing, in pt.

leading is the side where text starts, and trailing is the side where text ends. In left-to-right languages leading is left and trailing is right; in right-to-left languages the two are swapped. The swapped effect is not verified in the simulator.

Fields are read-only; to change one, replace the whole struct with a new one. Where a struct is accepted on write, a plain object with all fields also works. Each property read gives a new object. These rules hold for all structs; see Structs.

Inheritance: None. NSDirectionalEdgeInsets is an ordinary JS class; it doesn't inherit from NSObject and isn't an EventTarget.

Constructor ​

NSDirectionalEdgeInsets()

Creates a set of insets from four numbers: top, the text-start side, bottom, and the text-end side. Arguments not given are 0.

Instance properties ​

PropertyDescription
top read-onlyTop inset, pt
leading read-onlyInset on the side where text starts, pt
bottom read-onlyBottom inset, pt
trailing read-onlyInset on the side where text ends, pt

Examples ​

js
const box = new UIView();
box.directionalLayoutMargins = new NSDirectionalEdgeInsets(1, 2, 3, 4);
console.log(String(box.layoutMargins));

Result: When the language is left-to-right, the console prints UIEdgeInsets(1, 2, 3, 4). directionalLayoutMargins and layoutMargins are the same margins.

Corresponding iOS API ​

ObjCJS
NSDirectionalEdgeInsetsMake(8, 16, 8, 16)new NSDirectionalEdgeInsets(8, 16, 8, 16)
NSDirectionalEdgeInsetsZeronew NSDirectionalEdgeInsets()

See also ​

  • Structs: rules shared by all structs, and converting to strings and JSON
  • Where it is used: directionalLayoutMargins on UIView
  • UIEdgeInsets: the version with fixed left and right