I've created a click-to-call button for use on mobile devices, but I cannot get it to work. It's just a standard button:
<a href="tel:+01845527445" title="Click to call 01845 527 445">
<span>01845 527 445</span>
</a>
The <span> wrapped around the number hides the text number itself, and instead shows a graphic button, which, when pressed, should trigger a call. The graphic button is used at the request of the client.
Can anyone suggest why this isn't working?
Thanks,
Kelly
Your requirement isn't possible to be implemented at the moment.
When you use a webview to make a call, you can't remove the alert as it is the UIWebView behaviour.
If you want, you can use the telprompt:// URL scheme. However, there is a risk that this URL scheme might get removed in future.
NSString *phoneNumber = #"1-545-554-1234";
NSString *phoneURLString = [NSString stringWithFormat:#"tel:%#", phoneNumber];
NSURL *phoneURL = [NSURL URLWithString:phoneURLString];
[[UIApplication sharedApplication] openURL:phoneURL];
Related
I'm using JSON in my app to call elements from a database.
One of these elements is a text block with href links.
The JSON looks like :
"textBlock":"<a href=\"http:\/\/www.website.com\/" target=\"_blank\">Link<\/a>
In my app I call label with :
self.TextLabel.text = self.item[#"textBlock"];
[selfTextLabel sizeToFit];
Result in my app shows :
Link
Would it be possible to write / strip this link properly ?
I came across this solution to strip the html, which works fine, but my links don't work, I would like to know if I can keep my links working.
OK, so after some more searching and trying, I finally got what I needed.
I first tried to put my string in UITextView, selectable with links detection. Would have been great if I had written directly my URLs in the text.
But again, the strings I receive from JSON look like :
Link
I looked at Fancy UILabels and NSDataDetector, but it seemed like the labels were working but still showing http:// which looked not good for me.
So I figured best way was to put this string in a UIWebView, and call it like (I replaced TextLabel in the question with TextView).
[self.TextView loadHTMLString:self.item[#"textBlock"] baseURL:nil];
I finally had some last issue, as the links were opening in the UIWebView instead of Safari.
So I added self.TextView.delegate = self; in viewDidLoad.
And
-(BOOL) webView:(UIWebView *)TextView shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
if ( inType == UIWebViewNavigationTypeLinkClicked ) {
[[UIApplication sharedApplication] openURL:[inRequest URL]];
return NO;
}
return YES;
}
.h file must also call UIWebViewDelegate.
And if you think UIWebView default font is ugly in this case, like I did, you can do :
NSString *nicerTextBlock = self.item[#"textBlock"];
[self.textView loadHTMLString:[NSString stringWithFormat:#"<style type='text/css'>body { font-family: Helvetica; font-size: 12 } ></style>%#", nicerTextBlock] baseURL:nil];
Hope this can spare some time for other people.
This is a very hard question, for all of you. Maybe some of you can answer it and if you do you are a life saver. Ok so my project is an RSS Feed which displays the news and when you click on it, it takes you to the page of the article. The website I am getting this feed from has menu and the user HAS to scroll down each time to view the full article. :(
So I know in WebView you can embed code into the web view, I was wondering if there was some code in HTML of how you can actually delete this menu. I add some screen shots. Look :
It is a Wordpress website, if you could give me the HTML code it would be awesome but it would be even better if you can give me the Xcode code to do this as well.
Thanks to everyone that takes the time to read / reply.
Use css to hide the menu:
#nav_menu-2 {
display: none;
}
In your context, you can automatically apply this change by injecting a Javascript script in your webview, which will apply the css rule to your element:
- (void)webViewDidStartLoad:(UIWebView *)webView
{
NSString *js = #"document.getElementById('nav_menu-2').style.display = 'none';";
[self.webView stringByEvaluatingJavaScriptFromString:js];
}
However, this is far from perfect as the js snippet will be executed after the page has finished loading, so the user will see the menu disappear.
EDIT:
If you don't want to reference the div's id, you could use the class widget_nav_menu:
- (void)webViewDidStartLoad:(UIWebView *)webView
{
NSString *js = #"var menus = document.getElementsByClassName('widget_nav_menu');"
"for (var i = 0; i < menus.length; i++) {"
"menus[i].style.display = 'none';"
"}";
[self.webView stringByEvaluatingJavaScriptFromString:js];
}
Beware that this will hide all elements with this class (but this could be what you need).
Can you supply a link or the html for the menu?
A frontend solution would be to use javascript/jQuery with something like:
<script>
$(document).ready(function(){
$('#your-menu-id').hide();
});
</script>
I tried to find the solution but can't. I need a custom image for Pinterest (Pin It) button and pin some custom image by url but not a current page.
I created a custom link:
Pin It
in style I set the background image but I see only default Pin It button and not my custom button
There are some solutions where you can set custom button image for Pin It button but I can't change the media={ImageURL} in those solutions.
The popular solution is
<a href='javascript:void((function()%7Bvar%20e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('charset','UTF-8');e.setAttribute('src','http://assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);document.body.appendChild(e)%7D)());'><img src='http://www.brandaiddesignco.com/blog/PinIt.png'/></a>
But it doesn't help me. Does any one know the solution?
Indeed the popular solution by Jeremy Mansfield at www.brandaiddesignco.com has a great method to customize the Pinterest button any way you want!
I've made three examples, in the form of jsFiddle's, so you can see how it's done using that method.
Reference: jsFiddle Text-Link method
Reference: jsFiddle Custom Logo method
Reference: jsFiddle Custom Logo and Image method
For more Pinterest Info, see my other SO Answer.
Adding an encoded whitespace before the last fragment of the URL will prevent Pinterest's JS from "hijacking" the link:
//pinterest.com/pin/create/%20button?url=
Update:
It seems that my previous solution doesn't work anymore. Here is another one:
//pinterest.com/pin/create%2Fbutton/?url=
At the risk of over simplifying things, use your 'http://pinterest.com/pin/create/button/?url=' path that you've already got, set up your variables, and append them as you do, and just don't include any pinterest javascript. Without that js, it won't find the link and replace it out with their own pinterest button. Just customize your link with an image inside it (or set a background image or whatever) and screw the pinterest js. Set the target to open in a new window.
Custom Link/Button looks like this:
<a href="http://stackoverflow.com/questions/11312923/custom-pinterest-button-for-custom-url-text-link-image-or-both" data-image="http%3A%2F%2Fcdn.sstatic.net%2Fstackexchange%2Fimg%2Flogos%2Fso%2Fso-logo.png" data-desc="Custom Pinterest button for custom URL (Text-Link, Image, or Both)" class="btnPinIt">
Custom Pin it image or text here!
</a>
Note: I don't think the data attributes need to be encoded (like I did for data-image) but it doesn't seem to hurt it.
JQuery:
$('.btnPinIt').click(function() {
var url = $(this).attr('href');
var media = $(this).attr('data-image');
var desc = $(this).attr('data-desc');
window.open("//www.pinterest.com/pin/create/button/"+
"?url="+url+
"&media="+media+
"&description="+desc,"_blank");
return false;
});
Here is what worked for me :
<img src="../img/custompinint.png" />
The attribute data-pin-custom is what I picked up from Pinterest documentation.
Hope this helps.
After a bit of trial and error, below is what worked for me. This response is a combination of #rharvey's response thread and another stack overflow post. This solution opens up a pop up to share content via pinterest.
Note: In order to prevent 2 windows from popping up you need to set a target. Below is the full solution:
<a href="http://stackoverflow.com/questions/11312923/custom-pinterest-button-for-custom-url-text-link-image-or-both" data-image="http%3A%2F%2Fcdn.sstatic.net%2Fstackexchange%2Fimg%2Flogos%2Fso%2Fso-logo.png" data-desc="Custom Pinterest button for custom URL (Text-Link, Image, or Both)" class="btnPinIt" target= "pinIt">
Custom Pin it image or text here!
</a>
<script>
$('.btnPinIt').click(function() {
var url = $(this).attr('href');
var media = $(this).attr('data-image');
var desc = $(this).attr('data-desc');
window.open("//www.pinterest.com/pin/create/button/"+
"?url="+url+
"&media="+media+
"&description="+desc,"pinIt","toolbar=no, scrollbars=no, resizable=no, top=0, right=0, width=750, height=320");
return false;
});
</script>
Works for me perfectly.
Your script
<script>
function pinIt()
{
var e = document.createElement('script');
e.setAttribute('type','text/javascript');
e.setAttribute('charset','UTF-8');
e.setAttribute('src','https://assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);
document.body.appendChild(e);
}
</script>
Call it with
Pin
I am taking a programming class (for noobs) and I need to create the UIViewController graphViewController's view programmatically (without interface builder).
The view is simple, it only consists of an IBOUtlet which is an instance of a UIView subclass called GraphView. graphView responds to several multitouch gestures for zooming and panning and what-not, but I handle all of that stuff in - (void)viewDidLoad.
I am doing just the creation of the self.view property and graphView in the code below:
- (void)loadView
{
UIView *gvcView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
self.view = gvcView;
[gvcView release];
GraphView *aGraph = [[GraphView alloc] initWithFrame:self.view.bounds];
self.graphView = aGraph;
[aGraph release];
}
When I run the app I do not see the graphView view in there. I just get a transparent view which shows the "My Universal App" label. I'm stumped. Please help.
Let me know if you need additional code.
Thanks!
Update: Big thanks to BJ Homer for the quick fix!
had to do the following:
add this line of code: [self.view addSubview:self.graphView]; at the end.
I was also getting this strange bug where graphView was showing up as completely black. This line of code fixed that: self.graphView.backgroundColor = [UIColor whiteColor];
And that's it!
Final question: Is the default background color black for a custom UIView?
Thanks again!
[self.view addSubview:self.graphView];
Until you add your graph view to a parent view, UIKit doesn't know where to display it. self.view is special, since that's the property that -loadView is supposed to set. That view will automatically be added to the screen. But your graph view is just floating off in the ether until you add it somewhere.
I'm building an very simple application and I would like to reduce the coding lines in it, and I would like to that by using one or two functions instead of 20.
The app displays 10 buttons. Each button has two buttons to display, both with the same action (sending an email) but each button has a different identity so it also has different email content. It works fine if I do a function for each button, but I know it's possible to simplify that, I just don't know how.
Can someone point me in the right direction? This is what I'm doing right now in my methods:
MFMailComposeViewController *controller1 = [[MFMailComposeViewController alloc] init];
controller1.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail]) {
[controller1 setToRecipients:[NSArray arrayWithObjects: #"dev#company.com", nil]];
[controller1 setSubject:#"Button 1"];
[controller1 setMessageBody:#"The second option form button 1 was selected" isHTML:NO];
[self presentModalViewController:controller1 animated:YES];
}
[controller1 release];
Set a unique tag (see the tag property) for each button and check the tag of the sender in your one -sendEmail: method. All your buttons call that one method.