Skip to content

UIEdgeInsets ​

UIEdgeInsets represents how far each of the four edges is inset: top, left, bottom, right, in pt. The four numbers start from the top edge and go counterclockwise: top, left, bottom, right.

left and right are always the left and right of the screen. When the UI needs to support right-to-left languages, use NSDirectionalEdgeInsets, whose left and right swap with text direction.

Fields are read-only, so to change one you replace the whole struct; where a struct is accepted on write, a plain object with all fields can also be given; each read of a property returns a new object. These rules hold for all structs; see Structs.

Inheritance: None. UIEdgeInsets is a plain JS class; it does not inherit from NSObject and is not an EventTarget.

Constructor ​

UIEdgeInsets()

Creates a set of insets from four numbers: top, left, bottom, right. Omitted arguments are 0.

Instance properties ​

PropertyDescription
top read-onlyTop inset, pt
left read-onlyLeft inset, pt
bottom read-onlyBottom inset, pt
right read-onlyRight inset, pt

Examples ​

js
const box = new UIView();
box.layoutMargins = new UIEdgeInsets(8, 16, 8, 16);
console.log(String(new UIEdgeInsets(8, 16, 8, 16)));

Result: box's layout margins become 8 pt at the top and bottom and 16 pt on the left and right. The console prints UIEdgeInsets(8, 16, 8, 16).

Corresponding iOS API ​

ObjCJS
UIEdgeInsetsMake(8, 16, 8, 16)new UIEdgeInsets(8, 16, 8, 16)
UIEdgeInsetsZeronew UIEdgeInsets()

See also ​

  • Structs: the rules shared by all structs, and converting to strings and JSON
  • Where it is used: layoutMargins and safeAreaInsets on UIView, contentInset on UIScrollView
  • NSDirectionalEdgeInsets: the version whose left and right swap with text direction