UIView
public extension UIView
-
Positions where a view may be placed, relative to a superview.
See moreDeclaration
Swift
enum Position -
Creates a SimpleAnimation that allows you to add different actions and transformations to the view, executing each of them only when the previous one is finished in the order they were added.
Declaration
Swift
func simpleAnimation() -> SimpleAnimationReturn Value
SimpleAnimation for this view
-
Creates a MixedAnimation that allows you to add different actions and transformations to the view, concatenating and executing first all transformations and when that is done, executes each action that was added.
Declaration
Swift
func mixedAnimation(withDuration duration: TimeInterval) -> MixedAnimationReturn Value
MixedAnimation for this view
-
Creates a ChainedAnimation that allows you to combine SimpleAnimations and MixedAnimations, and execute them in the order they were added.
Declaration
Swift
func chainedAnimation(loop: Bool = false) -> ChainedAnimationReturn Value
ChainedAnimation for this view
-
Adds a shake animation that executes the closure when long pressed
Declaration
Swift
func shake(withDuration duration: TimeInterval = 0.05, repeatShake: Float = 3)Parameters
durationTime in seconds the animation will be executed. Default is 0.05
repeatShakeNumber of times the view will change position. Default is 3
-
Allows dragging the view and executing actions when the press gesture begins or ends.
Declaration
Swift
func isDraggable(returnToPosition: Bool = true, withDuration duration: TimeInterval = 0.5, onDragStarted: ((UIView) -> Void)?, onDragFinished: ((UIView) -> Void)?)Parameters
returnToPositionWhether the view will return to its original position when released. Default is true
durationTime in seconds that it takes for the view to return to the original position. Default is 0.5
onDragStartedThe closure that will execute when the view is held
onDragFinishedThe closure that will execute when the view is released
-
Loads the view into the specified containerView.
Note
If you decide to use constraints to determine the size, the container’s frame doesn’t need to be final. Because of this, it can be used in
loadView(),viewDidLoad()orviewWillAppear(animated:). We strongly recommend to work with constraints as a better practice than frames. Also, this function matches left inset to leading and right to trailing of the view.Declaration
Swift
func add(into containerView: UIView, with insets: UIEdgeInsets = .zero, in viewPositioning: ViewPositioning = .front, layout: LayoutMode = .constraints, respectSafeArea: Bool = false)Parameters
containerViewThe container view.
insetsInsets that separate self from the container view. By default, .zero.
viewPositioningBack or Front. By default, .front.
layoutEnum indicating the layout mode. By default, .constraints.
-
Adds a border to the top of the view, inside the view’s bounds.
Note
If you decide to use constraints to determine the size, self’s frame doesn’t need to be final. Because of this, it can be used in
loadView(),viewDidLoad()orviewWillAppear(animated:). We strongly recommend to work with constraints as a better practice than frames.Declaration
Swift
@discardableResult func add(top border: BorderViewProperties, withLeftOffset left: CGFloat = 0, rightOffset right: CGFloat = 0, layout: LayoutMode = .constraints) -> BorderViewParameters
borderModels characteristics of the border to be added.
leftOffsetOffset from the view’s left border to where the border should start. By default, 0.
rightOffsetOffset from the view’s right border to where the border should start. By default, 0.
layoutEnum indicating the layout mode. By default, .constraints.
-
Adds a border to the bottom of the view, inside the view’s bounds.
Note
If you decide to use constraints to determine the size, self’s frame doesn’t need to be final. Because of this, it can be used in
loadView(),viewDidLoad()orviewWillAppear(animated:). We strongly recommend to work with constraints as a better practice than frames.Declaration
Swift
@discardableResult func add(bottom border: BorderViewProperties, withLeftOffset left: CGFloat = 0, rightOffset right: CGFloat = 0, layout: LayoutMode = .constraints) -> BorderViewParameters
borderModels characteristics of the border to be added.
leftOffsetOffset from the view’s left border to where the border should start. By default, 0.
rightOffsetOffset from the view’s right border to where the border should start. By default, 0.
layoutEnum indicating the layout mode. By default, .constraints.
-
Adds a border to the left of the view, inside the view’s bounds.
Note
If you decide to use constraints to determine the size, self’s frame doesn’t need to be final. Because of this, it can be used in
loadView(),viewDidLoad()orviewWillAppear(animated:). We strongly recommend to work with constraints as a better practice than frames.Declaration
Swift
@discardableResult func add(left border: BorderViewProperties, withTopOffset top: CGFloat = 0, bottomOffset bottom: CGFloat = 0, layout: LayoutMode = .constraints) -> BorderViewParameters
borderModels characteristics of the border to be added.
leftOffsetOffset from the view’s left border to where the border should start. By default, 0.
rightOffsetOffset from the view’s right border to where the border should start. By default, 0.
layoutEnum indicating the layout mode. By default, .constraints.
-
Adds a border to the right of the view, inside the view’s bounds.
Note
If you decide to use constraints to determine the size, self’s frame doesn’t need to be final. Because of this, it can be used in
loadView(),viewDidLoad()orviewWillAppear(animated:). We strongly recommend to work with constraints as a better practice than frames.Declaration
Swift
@discardableResult func add(right border: BorderViewProperties, withTopOffset top: CGFloat = 0, bottomOffset bottom: CGFloat = 0, layout: LayoutMode = .constraints) -> BorderViewParameters
borderModels characteristics of the border to be added.
leftOffsetOffset from the view’s left border to where the border should start. By default, 0.
rightOffsetOffset from the view’s right border to where the border should start. By default, 0.
layoutEnum indicating the layout mode. By default, .constraints.
-
Removes the border view from self, only if the border was a child view to self.
Declaration
Swift
func remove(border: BorderView) -
Adds borders to the selected sides of the view, inside the view’s bounds.
Note
If you decide to use constraints to determine the size, self’s frame doesn’t need to be final. Because of this, it can be used in
loadView(),viewDidLoad()orviewWillAppear(animated:). We strongly recommend to work with constraints as a better practice than frames.Declaration
Swift
func addBorders(properties: BorderViewProperties, positions: [BorderPosition], layout: LayoutMode = .constraints)Parameters
propertiescharacteristics of the borders to be added.
positionsthe sides of the view where borders will be added.
layoutEnum indicating the layout mode. By default, .constraints.
-
Adds a drop shadow to the selected view.
Note
If you decide to use constraints to determine the size, self’s frame doesn’t need to be final. Because of this, it can be used in
loadView(),viewDidLoad()orviewWillAppear(animated:). We strongly recommend to work with constraints as a better practice than frames.Declaration
Swift
func addShadow(color: CGColor = UIColor.black.cgColor, size: CGSize = CGSize(width: 0, height: 2), radius: CGFloat = 2.5, opacity: Float = 0.2, cornerRadius: CGFloat = 5)Parameters
colorthe color of the shadow.
sizehorizontal and vertical size of the shadow.
radiusthe overall extension of the shadow from the center of the view.
cornerRadiushow rounded the corners of the shadow are.
-
addLongPressGestureRecognizer(numberOfTapsRequired:numberOfTouchesRequired: minimumPressDuration: allowableMovement: action: ) Adds a long-press gesture recognizer that executes the closure when long pressed
Declaration
Swift
func addLongPressGestureRecognizer(numberOfTapsRequired: Int = 0, numberOfTouchesRequired: Int = 1, minimumPressDuration: TimeInterval = 0.5, allowableMovement: CGFloat = 10, action: ((UILongPressGestureRecognizer) -> Void)?)Parameters
numberOfTapsRequiredThe number of full taps required before the press for gesture to be recognized. Default is 0
numberOfTouchesRequiredNumber of fingers that must be held down for the gesture to be recognized. Default is 1
minimumPressDurationTime in seconds the fingers must be held down for the gesture to be recognized. Default is 0.5
allowableMovementMaximum movement in pixels allowed before the gesture fails. Once recognized (after minimumPressDuration) there is no limit on finger movement for the remainder of the touch tracking. Default is 10
actionThe closure that will execute when the view is long pressed
-
Adds a pan gesture recognizer that executes the closure when panned
Declaration
Swift
func addPanGestureRecognizer(minimumNumberOfTouches: Int = 1, maximumNumberOfTouches: Int = .max, action: ((UIPanGestureRecognizer) -> Void)?)Parameters
minimumNumberOfTouchesThe minimum number of touches required to match. Default is 1
maximumNumberOfTouchesThe maximum number of touches that can be down. Default is Int.max
actionThe closure that will execute when the view is panned
-
Adds a pinch gesture recognizer that executes the closure when pinched
Declaration
Swift
func addPinchGestureRecognizer(action: ((UIPinchGestureRecognizer) -> Void)?)Parameters
actionThe closure that will execute when the view is pinched
-
Adds a rotation gesture recognizer that executes the closure when rotated
Declaration
Swift
func addRotationGestureRecognizer(action: ((UIRotationGestureRecognizer) -> Void)?)Parameters
actionThe closure that will execute when the view is rotated
-
Adds a screen-edge-pan gesture recognizer that executes the closure when panned on the edge
Declaration
Swift
func addScreenEdgePanGestureRecognizer(edge: UIRectEdge, action: ((UIScreenEdgePanGestureRecognizer) -> Void)?)Parameters
edgeThe edge on which this gesture recognizes, relative to the current interface orientation.
actionThe closure that will execute when the edge of the view is panned
-
Adds a swipe gesture recognizer that executes the closure when swiped
Declaration
Swift
func addSwipeGestureRecognizer(numberOfTouchesRequired: Int = 1, direction: UISwipeGestureRecognizer.Direction = .right, action: ((UISwipeGestureRecognizer) -> Void)?)Parameters
numberOfTouchesRequiredThe number of fingers that must swipe. Default is 1
directionThe desired direction of the swipe. Multiple directions may be specified if they will result in the same behavior (for example, UITableView swipe delete). Default is right
actionThe closure that will execute when the view is swiped
-
Adds a tap gesture recognizer that executes the closure when tapped
Declaration
Swift
func addTapGestureRecognizer(numberOfTapsRequired: Int = 1, numberOfTouchesRequired: Int = 1, action: ((UITapGestureRecognizer) -> Void)?)Parameters
numberOfTapsRequiredThe number of taps required to match. Default is 1
numberOfTouchesRequiredThe number of fingers required to match. Default is 1
actionThe number of fingers required to match. Default is 1
-
ViewGradient applied currently to the view. A view can only have one gradient at a time. When setting this property to a new gradient, the old one will be removed, and when set to .none the current one will be removed. The gradient will always have the same direction in relation to the view’s orientation at a certain time. The gradient will always acommodate to the view’s change in size or orientation.
Warning
To avoid memory leak and crashes, you should set thegradientto .none before deallocating the view.Declaration
Swift
var gradient: ViewGradient? { get set } -
This is an extension for layout compatibility between iOS 11 and lower versions. If the native safe layout guide is not available, then return a regular layout guide.
Declaration
Swift
var safeLayoutGuide: UILayoutGuide { get } -
Indicates wether this functionality is available (iOS 11.0 or newer).
Declaration
Swift
var safeLayoutInsets: UIEdgeInsets { get }
UIView Extension Reference