I'd like to add UIButton to my UIViewController. I have a UIPageViewController on all screen. When I'm trying to add this button... there is no button on the sreen visible. What do I do wrong?
CODE:
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(setButtonVisibleClose:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Zamknij widok" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
button.backgroundColor = [UIColor whiteColor];
[self.view addSubview: button];
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageController.dataSource = self;
[[self.pageController view] setFrame:[[self view] bounds]];
BasicViewViewController *initialViewController = [self viewControllerAtIndex:0];
[initialViewController setImageViewToDisplay];
NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];
[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:self.pageController];
[[self view] addSubview:[self.pageController view]];
[self.pageController didMoveToParentViewController:self];
Your problem is likely that you added the button as a subview first, and then created the page controller and added it's view "on top of" the button. Subviews added first are always by default placed under subviews that are added later.
If you move the button creation code to after the page controller code in that method, your button should appear on top of the page controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With