Add button horizontally to Page Control - objective-c

I need to add a button horizontally to a Page Control in UIPageViewController. I have added my pageviewcontroller as a subview to a ViewController, by default im getting the page control .Now I wanted to add a button, Can anyone suggest any way to add button ?
Thanks in advance!!
_pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options:nil];
self.view.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.5];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:
#"Main" bundle:[NSBundle mainBundle]];
UIViewController *p1 = [storyboard instantiateViewControllerWithIdentifier:#"First"];
UIViewController *p2 = [storyboard
instantiateViewControllerWithIdentifier:#"Second"];
UIViewController *p3 = [storyboard
instantiateViewControllerWithIdentifier:#"Third"];
UIViewController *p4 = [storyboard
instantiateViewControllerWithIdentifier:#"Fourth"];
_Array = #[p1,p2,p3,p4];
_pageViewController.dataSource = self;
_pageViewController.delegate = self;
[_pageViewController setViewControllers:#[_Array[0]]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
[_pageViewController willMoveToParentViewController:self];
[self addChildViewController:_pageViewController];
[self.view addSubview:_pageViewController.view];
[self.view sendSubviewToBack:self.pageViewController.view];
[_pageViewController didMoveToParentViewController:self];

I believe this is what youre looking for. He explains in detail how to add the buttons "on top of " your page view controller view. You can do this after you add the page view controller, you can use the sendSubviewToBack method to ensure that the buttons remain in the foreground while you will be able to swipe between the different view controllers of your page view controller. Have a look here

you can extract the view where page control is kept on, then you can do what ever you want. Below is the code for extracing the pagecontrol view:
NSArray *subviews = self.pageController.view.subviews;
for (int i=0; i<[subviews count]; i++) {
if ([[subviews objectAtIndex:i] isKindOfClass:[UIPageControl class]]) {
self.pageControl = (UIPageControl *)[subviews objectAtIndex:i];
}
}
UIView *pageControlBaseView = [[UIView alloc] initWithFrame:CGRectMake(0,60,100, 40)];
[pageControlBaseView addSubview:self.pageControl];
self.pageControl.pageIndicatorTintColor = [UIColor redcolor];
self.pageControl.currentPageIndicatorTintColor = [UIColor greencolor];
[self.view addSubview:pageControlBaseView];
please let me know if you need more clarity.

Related

presentViewController shows black sceen while UIModalTransitionStyleFlipHorizontal objective c

I'm facing issue with the UIModalTransitionStyleFlipHorizontal, Which gives black screen at background while transition and shows the actual screen.
After first time it shows the last view which added as rootview.
What actually I need to achieve is I don want to show the black and previous screen. It should show an empty screen background as like the below image.
The code I used to achieve the transition is
- (void)popViewController {
UIViewController* rootController = [[UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:#"MainViewController"];
rootController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:rootController];
[self.window.rootViewController presentViewController:navigation animated:YES completion:nil];
[self.window makeKeyAndVisible];
}
I'm using storyboard with dynamic rootview.Anybody help me to fix it out.
Thanks
Remove subview
Add this code on your method popViewController
AppDelegate *appDelegate =(AppDelegate *)[[UIApplication sharedApplication]delegate];
NSArray *subViewArray = [appDelegate.window subviews];
for (id obj in subViewArray)
{
[obj removeFromSuperview];
}
I solved the issue by add window subview with background.
UIImageView* background = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.window.frame.size.width, self.window.frame.size.height)];
background.image = [UIImage imageNamed:#"TermsBg"];
[self.window addSubview:background];

UINavigationController rightbarbuttonitem not showing

after going through the questions related to UINavigationController item i came to post my exact problem ..
firstly i am not add a UINavigationController in MainWindow.xib i created and adding UINavigationController in AppDelegate file
after that in a UIViewController (not in rootViewController) class I have to add a rightbarbutton of Done type I am
adding it in a searchbarDelegate Method showing as bold:-
- (void) searchBarTextDidBeginEditing:(UISearchBar *)theSearchBar {
//This method is called again when the user clicks back from teh detail view.
//So the overlay is displayed on the results, which is something we do not want to happen.
if(exhibDataObj.searching)
return;
//Add the overlay view.
if(ovController == nil)
ovController = [[OverlayViewController alloc] initWithNibName:#"OverlayView" bundle:[NSBundle mainBundle]];
CGFloat yaxis = self.navigationController.navigationBar.frame.size.height;
CGFloat width = self.view.frame.size.width;
CGFloat height = self.view.frame.size.height;
//Parameters x = origion on x-axis, y = origon on y-axis.
CGRect frame = CGRectMake(0, yaxis, width, height);
ovController.view.frame = frame;
ovController.view.backgroundColor = [UIColor grayColor];
ovController.view.alpha = 0.5;
ovController.rvController = self;
[self.theTableView insertSubview:ovController.view aboveSubview:self.parentViewController.view];
exhibDataObj.searching = true;
letUserSelectRow = NO;
self.theTableView.scrollEnabled = NO;
//Add the done button.
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self action:#selector(doneSearching_Clicked:)];
}
but this never works .
Any help will be more appreciable.
I've tested your code real quick and it seems to be working fine for me, however, I've had the same problem once back then it turned out I was setting the rightBarButtonItem to nil in my viewDidLoad method after setting it to a button. you should make sure your not making the same mistake somehow.
However if that does not work for you you can always try setting a custom button to it:
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 5, 30, 30)];
button.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"done.png"]];
[button addTarget:self action:#selector(doneButtonClicked) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationController.visibleViewController.navigationItem.rightBarButtonItem = customItem;

presentModalViewController in UISplitViewControllers detailView not presenting the view in full screen

I have added the UISplitViewController view in my mainViewControllers view, the code is below.
documentsRootViewController = [[DocumentsRootViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:documentsRootViewController];
documentsRootViewController.title = #"Document List";
documentDetailView = [[DocumentsDetailView alloc] initWithNibName:#"DocumentsDetailView" bundle:nil];
documentsRootViewController.detailViewController = documentDetailView;
docSplitViewController = [[UISplitViewController alloc] init];
docSplitViewController.viewControllers = [NSArray arrayWithObjects:navigationController, documentDetailView, nil];
docSplitViewController.delegate = documentDetailView;
CGRect splitViewFrame = CGRectMake(0, 0, cetralArea.frame.size.width, cetralArea.frame.size.height);
docSplitViewController.view.frame = splitViewFrame;
[cetralArea addSubview:docSplitViewController.view];
now what I want is to present a ViewController from the DetailView of the UISplitViewController I am trying to do it as below inside the DetailViewControllers Click Me! buttons click.
- (IBAction) buttonClicked:(id)sender
{
NSString *phrase = nil; // Document password (for unlocking most encrypted PDF files)
NSArray *pdfs = [[NSBundle mainBundle] pathsForResourcesOfType:#"pdf" inDirectory:nil];
NSString *filePath = [pdfs lastObject]; assert(filePath != nil); // Path to last PDF file
ReaderDocument *readerDocument = [ReaderDocument withDocumentFilePath:filePath password:phrase];
if (readerDocument != nil) // Must have a valid ReaderDocument object in order to proceed with things
{
ReaderViewController *rViewController = [[ReaderViewController alloc] initWithReaderDocument:readerDocument];
rViewController.delegate = self; // Set the ReaderViewController delegate to self
[self presentModalViewController:rViewController animated:NO];
}
}
but this is resulting in an awkward presentation
can anyone suggest what is the problem here, thanks in advance..
In your screenshots I can't really tell where is your split view controller left side and right side (detail view) located. Change background colors of the views to distinguish positions. Seems you are having problems with them.
Anyways, you can try presenting the modal view controller from the splitView instead of the Detail.
[splitViewController presentModalViewController:rViewController animated:NO];
I believe the trick here is changing the modalPresentationStyle (and optionally modalTransitionStyle) of the view controller that you want to display modally:
ReaderViewController *rViewController = [[ReaderViewController alloc] initWithReaderDocument:readerDocument];
rViewController.delegate = self; // Set the ReaderViewController delegate to self
rViewController.modalPresentationStyle = UIModalPresentationFullScreen;
rViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:rViewController animated:YES completion:nil];
I had the same problem (in iOS 5.1). Set the modalPresentationStyle to UIModalPresentationPageSheet and it should work as expected.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
rViewController.modalPresentationStyle = UIModalPresentationPageSheet;
rViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
}
What i found is you are giving splitview size like cetralArea.frame.size.width.
Instead of that simply give directly size that you want to give to the Splitview.
Hope it will work for you.

UIButton UIPopUpController programmatically

having difficulty getting UIButton Items to show.. I want to place several UIButtons within my UIPopUpController. I'm doing everything in a storyboard and I need to do this section programmatically.
- (void)showPopover:(id)sender
{
if(![popoverController isPopoverVisible])
{
myPopOver = [[PopUp alloc] init];
popoverController = [[UIPopoverController alloc] initWithContentViewController:myPopOver] ;
[popoverController setPopoverContentSize:CGSizeMake(300, 200.0f)];
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
CGRect rect = (CGRect)[sender frame];
rect.origin.y = self.view.frame.size.height - rect.size.height;
[popoverController presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
else
{
[popoverController dismissPopoverAnimated:YES];
}
}
You could use a UINavigationController (it has already a navigation bar where you can attach buttons items) and add it as the content of your UIPopoverController. The UINavigationController can be istantiated using the initWithRootViewController method. In this case the controller would be your Popup class. For example, inside your showPopover method, you could do the following:
PopUp* myPopOver = [[PopUp alloc] init];
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:myPopOver];
popoverController = [[UIPopoverController alloc] initWithContentViewController:navController];
// do other stuff here to present you UIPopoverController
[myPopOver release];
[navController release];
Now, inside your PopUp class, within viewDidLoad method, you can customize the UINavigationController navigationBar. For example:
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *aButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Show" style:UIBarButtonItemStylePlain target:self action:#selector(somethingSelector:)];
self.navigationItem.rightBarButtonItem = aButtonItem;
[aButtonItem release];
}
where somethingSelector is like the following:
- (void)somethingSelector:(id)sender
{
// your custom actions
}
EDIT
Alternatively you can avoid to use the UINavigationController and create UIToolbar inside your PopUp class. Inside the UIToolbar you can attach UIBarButtonItems. See UIToolbar Class Reference

setModalTransitionStyle and setModalPresentationStyle, set size of view

I create a UIViewController (a custom calendar and its size is 550x440) and when i push a button it must be appear; the problem is that if I use setModalPresentationStyle and setModalTransitionStyle they change size of my view; can I set the size for these presentation?
I find a solution:
[self presentModalViewController:calendar animated:YES];
calendar.view.superview.frame = CGRectMake(0, 0, 200, 200);
Maybe you want to change your design to implement your calendar as a popover:
// Define the size of the calendar view controller for the popover
UIViewController *viewController = [[UIViewController alloc] init];
viewController.contentSizeForViewInPopover = CGSizeMake(550.0f, 440.0f);
viewController.delegate = self;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
// Create the popover
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:navigationController];
// Present the popover from one button
[popoverController presentPopoverFromBarButtonItem:button permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
//release the popover content
[viewController release];
[navigationController release];