6

What is superview and what is subviews?

When I add this code:

[self.view addSubview:self.frontView];
// what does that mean ?

And...

@property (nonatomic, strong) IBOutlet UIImageView *frontView;
[self.frontView superview] != nil // means ?

what is in superview?

gsamaras
  • 71,951
  • 46
  • 188
  • 305
Edward Anthony
  • 3,354
  • 3
  • 25
  • 40

4 Answers4

21

A superview is a view that holds other views over it and subviews are the views being held/added over a View.

Let's assume we have a view named MyView, which holds a UIButton (named loginButton) over it. Here MyView is considered a superview for loginButton and loginButton is considered a subview of MyView.

For more, you should start from here

As per the provided code snippet.

[self.view addSubview:self.frontView];

Hence view (Controller's view) is a superview and frontView is a subview

Kamar Shad
  • 6,089
  • 1
  • 29
  • 56
5

"superview" means the view which holds the current one. "subviews" means the views which are holding by the curent view.

For example, you have a view (will call it as MyView) which include a button. Button is a view too (UIButton is a kind of view). So, MyView is superview for the button. Button is a subview for MyView.

Ivan Surzhenko
  • 149
  • 1
  • 8
1

See Apple's View Programming Guide, section View Hierarchies and Subview Management

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
1

subview is childview ( which is added on any view)

superview is parentview (on which subview is added)

abhishekkharwar
  • 3,529
  • 2
  • 18
  • 31