0

I'm trying to show an onscreen tutorial (like a picture with hints) in my viewController. I only know how to "open" a UIView with its drawRect method, where my paint code is inside, from the AppDelegate with:

BannerView *view = [[BannerView alloc] initWithFrame:self.window.frame];
[self.window addSubview:view];
[self.window makeKeyAndVisible];

Is it possible to activate the UIView (BannerView) by a button from inside a ViewController?

Thank you very much!

Bejmax
  • 945
  • 7
  • 16
Linus
  • 4,643
  • 8
  • 49
  • 74

2 Answers2

1

I believe what you are looking for is adding an event handler to a button on the view controller that will create the view and add the view by using something like

BannerView *view = [[BannerView alloc] initWithFrame:CGRectMake(x,y,width,height)];
[self.view addSubview:view];

where self is the view controller.

Tony
  • 4,609
  • 2
  • 22
  • 32
1

Simply use this code:

BannerView *view = [[BannerView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:view];

in your button action method (if it is defined in your controller class). See this S.O. question to know how to create a button programmatically. Otherwise, you can use interface builder for that.

Using self.view.bounds in initWithFrame will make your banner view as large as the controller's view (which could be smaller than the display).

Community
  • 1
  • 1
sergio
  • 68,819
  • 11
  • 102
  • 123