Search code examples
iosuiwebviewuibuttonnsdata

Set up hidden button on UIwebview page


1.I am working on UIWebView and I wanna to ask how do set up hidden button on the UIWebView or navigation bar (with buttons on) I want to implement tap screen to show those buttons. Can anyone give me some suggestions?

2.I am using http get to get image from such address:10.103.198.246:85/snapshot.cgi (api only support get method) how do I display that image using returning data?

NSURL *url1 =[NSURL URLWithString:@"http://@10.103.198.246:85/snapshot.cgi"];
              NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url1 cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10];
              NSData *received = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *str = [[NSString alloc]initWithData:received encoding:NSUTF8StringEncoding];

NSLog(@"%@",str);

This how I get text info. but how do i display image data? Thanks!


Solution

    1. Add a Tap gesture recognizer to the UIWebView. On the tap event, add a semi-transparent view to the WebView and add the buttons you need to that new view.

    2. UIImage has an -initWithData: method that you can use to get the UIImage object. Not sure in a .cgi extension is supported, might only by common formats like .jpg or .png

      UIImage *img = [[UIImage alloc]initWithData:received.....];