0

(iPad, iOS7, xCode5)

I'm using a modal to display .pdf documents, full-screen.

Example: user taps button entitled, "View PDF." Said document is shown using a modal view, full-screen.

How can I add a close button?

I've successfully added a navigation controller, and placed therein a view controller containing the Web View, but then I end up with a long unused strip at the top, with nothing but a "Done" button.

.pdf loads without issue. They display full-screen (inside the Web View, sized to take up the entire viewport).

What I'd like is much like how the MPMoviePlayerController video player class works: Have a menu bar show/hide on a tap gesture.

Alternatively, is there a way to position a "Done" button at the top-right?

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSString *path = [[NSBundle mainBundle] pathForResource:@"typesOfBrieCheese" ofType:@"pdf"];

NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[self.PdfWebView loadRequest:request];
}

Thanks for your help.

Sincerely, Keith :)

Larme
  • 24,190
  • 6
  • 51
  • 81
kmiklas
  • 13,085
  • 22
  • 67
  • 103
  • I think would you need to look at adding uibarbuttonitem's http://stackoverflow.com/questions/13798815/how-to-add-button-to-navigation-controller that's just an example of a post covering adding buttons. – LanternMike May 01 '14 at 16:14

3 Answers3

0

I ended up scrapping the navigation controller, and put the "Done" button and Web View inside a UIViewController.

I just had to make sure that the "Done" button was lower down in the hierarchy, so that it shows over the top of the Web View.

Note that this app is not for submission to the App store.

kmiklas
  • 13,085
  • 22
  • 67
  • 103
0

Okay so you said you succesfully added a navigation controller and you place therein a view controller. Placing a view controller in a navigation controller automatically gives that view controller a navigation bar on top. On this bar you can drag and drop a UIBarbutton (Thats if ofcourse you are using storyboard) on it. You can either place it on the right or left.

After doing that , make you you resize your webview so that it doesn't overshadow the navigation bar. Click on the bar button you put on the navigation bar and on the right side , you can either decide to customize the button to whatever name you wish or select a name for from the default list. After that click on the Show Assistant Editor. Check to see whether it has opened the correct .h file for you. Connect your button to the code by placing your hand on the control button and dragging the bar button to the code. Select "Action" and specify your identifier.

After go to the .m file , scroll to the end of the page , an action function will be there waiting for you for that buttom. Place this line of code in it.

-(IBAction)identifier:(id)sender

[self dismissViewControllerAnimated:YES completion:Nil];
0

You can use Weview inside button by pasting the below code

UIButton *webviewbutton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[webviewbutton addTarget:self 
           action:@selector(closeAd:)
 forControlEvents:UIControlEventTouchUpInside];
[webviewbutton setTitle:@"Close" forState:UIControlStateNormal];
webviewbutton.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[self.webview addSubview:button];
sugansoft
  • 1,227
  • 8
  • 26