You can add padding to the top of a UIView in Swift by setting its topAnchor
constraint with a constant value. Here's an example:
main.swift227 chars7 lines
In this example, myView
is a newly created UIView
. You need to add myView
to a superview first and set its constraints to make it fill the superview. Then, you can set its topAnchor
constraint with a constant value of 20
, which will add a padding of 20
points to the top of myView
.
gistlibby LogSnag