-1

What´s the difference between view and superview?

let fromViewController = self.source

let containerView = fromViewController.view.superview
rmaddy
  • 314,917
  • 42
  • 532
  • 579
SwiftiSwift
  • 7,528
  • 9
  • 56
  • 96

2 Answers2

3

Suppose that

let v1 = UIView()
parent.addSubview(v1)

here

v1 ----- >>> v1 ( The view itself )

v1.superview ------- >>> parent

Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
2

Views are the fundamental building blocks of your app's user interface, and the UIView class defines the behaviors that are common to all views. A view object renders content within its bounds rectangle and handles any interactions with that content.

let rect = CGRect(x: 10, y: 10, width: 100, height: 100) let myView = UIView(frame: rect)

The superview is the immediate ancestor of the current view. The value of this property is nil when the view is not installed in a view hierarchy. To set the value of this property, use the addSubview(_:) method to embed the current view inside another view.

let rect = CGRect(x: 10, y: 10, width: 100, height: 100) let myView = self.view.addSubview( UIView(frame: rect))