Exploring the gui
This presentation is the property of its rightful owner.
Sponsored Links
1 / 11

Exploring the GUI PowerPoint PPT Presentation


  • 105 Views
  • Uploaded on
  • Presentation posted in: General

Exploring the GUI. What if we want to add a UIView (for example a UILabel) at run time inside the navigation bar? We need to access that view, create a label, and add it as a subview How do we find that view?. Exploring the GUI. From a UIView named myView, we can go up

Download Presentation

Exploring the GUI

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Exploring the gui

Exploring the GUI

  • What if we want to add a UIView (for example a UILabel) at run time inside the navigation bar?

  • We need to access that view, create a label, and add it as a subview

  • How do we find that view?


Exploring the gui1

Exploring the GUI

  • From a UIView named myView, we can go up

  • myView.superview (a UIView)

  • or down

  • myView.subviews (a NSArray of UIViews)


Exploring the gui2

Exploring the GUI

  • From a UIViewController named myVC, we can go up

  • myVC.parentViewController (a UIViewController)

  • or down

  • myVC.childViewControllers (a NSArray of UIViewControllers)


Exploring the gui3

Exploring the GUI

  • Inside the DetailViewController, get the parent view controller, look at its view, and the children of its view

  • UIViewController *parentC = self.parentViewController;

  • UIView *topView = parentC.view;

  • NSArray *views = topView.subviews;


Exploring the gui4

Exploring the GUI

  • Use NSLog to output the views: there are 2 of them

  • iPad dimensions are:

  • UINavigationTransitionView: 0, 0, 703, 768

  • UINavigationBar: 0, 20, 703, 44

  •  navigation bar is on top and its height is 44 pixels


Exploring the gui5

Exploring the GUI

  • Get the navigation bar view

  • UINavigationBar *bar = (UINavigationBar *) [views objectAtIndex: 1];

  • Now place a label inside it


Exploring the gui6

Exploring the GUI

  • Run the app, back and forth

  • The label stays when we go back

  • Inside the viewWillAppear method of MasterViewController, we can remove it


Exploring the gui7

Exploring the GUI

  • If we have a method named removeLabel in the DetailViewController class, we could call it from viewWillAppear inside the MasterViewController class

  • [self.detailViewController removeLabel];


Exploring the gui8

Exploring the GUI

  • Inside removeLabel, we could search for the label, based on some characteristics (class name, color, text, ..)

  • Better, we can tag it when we add it

  • UIView has a property named tag (NSInteger)

  • label.tag = 99;


Exploring the gui9

Exploring the GUI

  • From a parent view, we can use the method viewWithTag (searches current view and subviews) to retrieve the label

  • UILabel *label = [someParentView viewWithTag: 99];

  • Now remove it

  • [label removeFromSuperview];


Exploring the gui10

Exploring the GUI

  • We could also declare the UILabel as an instance variable, create it when the view loads, and then set it visible or invisible using the hidden property

  • label.hidden = YES;

  • label.hidden = NO;


  • Login