"By clicking Register you are agreeing to our Terms and Conditions"
What is the easiest option to implement in the code where the entire above line is made clickable (this launches a modal view that shows the terms and conditions) AND the word "terms and conditions" is underlined in blue.
We tried various options.
1) We created a UIWebView and tried loading a html into it. But the html was rendered as is.
eg: "html body.../body html"
2) We tried to create a button with a label over it but we were not able to create a borderless button.
Thanks!
We were able to create the formatting by using a webView. We used one of the delegate of webView to complete the process. Here is sample code
NSString *html = #"<html><head><title>Terms and Conditions</title></head><body style=\"font-family:verdana;font-size:10px;\"><p>By clicking \"Register\" you are agreeing to our <b><u><font color=\"blue\">Terms and Conditions.</font></u></b></p></body></html>";
[termsWOutlet loadHTMLString:html baseURL:[NSURL URLWithString:#"http://www.google.com/message"]];
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(#"%s",__FUNCTION__);
NSURL* u = [request URL];
if( [[u scheme] isEqualToString:#"showlicenses"] ) {
NSLog(#"in %s",__FUNCTION__);
[self performSegueWithIdentifier:#"loadTNC" sender:self];
return NO; // DO NOT attempt to load URL
}
return YES; // if you want to allow the URL to load
}
Related
Say there's a custom link embedded in a WebUIView, and I would want to redirect a user not to Safari but to a different screen in the app. Is it possible to change the click handler for that link?
You can assign a delegate to the webView and use the webView:shouldStartLoadWithRequest:navigationType: method to detect the links you want a return NO.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if ([[request.URL absoluteString] isEqualToString:#"http://www.customurl.com"]) {
// Do something
return NO;
} else {
return YES;
}
}
You may also want to check the navigationType against UIWebViewNavigationTypeLinkClicked.
I want to open my UIImagePickerController when user taps on file input field in UIWebView. Currently UIWebView opens its own UIIMagePickerController on which I don't have any control.
One way to do it would be to change the url when the user taps on the file input field. There's an answer about doing something similar here: Is it possible to update a url link based on user text input?
Then your UIWebView will need to catch that url change and open your UIImagePickerController. That can easily be done with this chunk of code:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSString *URLString = [[request URL] absoluteString];
if ([URLString isEqualToString:#"http://www.mywebsite.com/selectpic.htm"])
{
// Your UIImagePickerController code here
}
return YES;
}
When you use the Facebook App and go to the Terms and Conditions view, there is a WebView. When you choose an option in the WebView you'll go to a new view.
Now I wanna make a login system with PHP. When the user login is succeded he'll go to an webpage. How can I set for example: When the UIWebView is on www.myserver.com/ok that the new view in my app will show?
Set your UIWebView with delegate and check :-
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSLog(#"Loading: %#", [request URL]); //if url matches www.myserver.com/ok open your view
return YES;
}
Hope it helps you..
I have a ios program for iPad. It is used 2 view, A view has webview, another has imageview. When I returned webview from imageview, webview is opened homepage. I want to return last page . How can I do?
If I understand you correctly, you want to make sure, that the last page that was loaded in the UIWebView will be displayed again when you switch back to the UIWebView.
To achieve that you can keep track of the last URL that was loaded in the UIWebView. You can do that in the following UIWebViewDelegate method (declare currentURL as property):
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
self.currentURL = request.URL;
return YES;
}
And then when you bring back your UIWebView:
- (void)showWebView {
[yourWebView loadRequest:[NSURLRequest requestWithURL:currentURL]];
}
I have UIView and UIWebView on screen. When I click on text field in website, web view content is going up. How could I force UIView to move as well then?
You can subscribe to either the UIKeyboardWillShowNotification or the UIKeyboardDidShowNotification, and move your UIView when you receive the notification. This process is described here:
Text, Web, and Editing Programming Guide for iOS: “Moving Content That Is Located Under the Keyboard”
Maybe this helps: I didn't want the UIWebView to scroll at all, including when focusing on a textfield.
You have to be the delegate of the UIWebView:
_webView.scrollView.delegate = self;
And then add this method
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
scrollView.contentOffset = CGPointZero;
}
UIWebView has a callback:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
This is triggered whenever a new URL request is about to load. From javascript, you could trigger a new request URL on the onfocus event of the tag, with a custom schema like:
window.location = "webViewCallback://somefunction";
Here's a script to put your custom event inside any html page to load.
You'll have to get the whole HTML before loading it to the UIWebView like this:
NSString *html = [NSString stringWithContentsOfURL:[NSURL URLWithString:#"your URL"] encoding:NSUTF8StringEncoding error:nil];
Then insert the following inside the HTML text in a appropriate place:
<script>
var inputs = document.getElementsByTagName('input');
for(int i = 0; i < inputs.length; i++)
{
if(inputs[i].type = "text")
{
inputs[i].onfocus += "javascript:triggerCallback()";
}
}
function triggerCallback()
{
window.location = "webViewCallback://somefunction";
}
</script>
Then, on the callback you should do something like this:
-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
if ( [[inRequest URL] scheme] == #"webViewCallback" ) {
//Change the views position
return NO;
}
return YES;
}
That's it. Hope it helps.
Wow, I had the same problem few days ago, it was really annoying. I figured out that window.yPageOffset is changing, but as far as I know there aren't any events to bind when it changes. But maybe it will help you somehow. ;-)
I think you overwrote scrollViewDidScroll wrong.
You need to implement custom class for UIWevView and overwrite scrollViewDidScroll:
- (void) scrollViewDidScroll:(UIScrollView *)scrollView{
[super scrollViewDidScroll:scrollView];
[((id<UIScrollViewDelegate>)self.delegate) scrollViewDidScroll:scrollView];
}