我正在以编程方式在我的应用程序中将Parse.com中的String提取到UILabel中。
字符串是电话号码。所以我的问题是,是否可以对单击后的UILabel进行操作以进行 call ..还是我必须从Button中获取数据,或者更好,这可能吗?
如果有可能,我应该怎么做?有人有我可以关注的示例或教程吗?
任何帮助,将不胜感激。
谢谢!
最佳答案
您的问题分为两部分:
首先,要在粘贴标签时执行操作,必须向该标签添加轻击手势识别器:
phoneNumberLabel.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGesture =
[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(phoneNumberLabelTap)];
[phoneNumberLabel addGestureRecognizer:tapGesture];
然后,您必须实现您的phoneNumberLabelTap方法:
-(void)phoneNumberLabelTap
{
NSURL *phoneUrl = [NSURL URLWithString:[NSString stringWithFormat:@"telprompt:%@",phoneNumberLabel.text]];
if ([[UIApplication sharedApplication] canOpenURL:phoneUrl]) {
[[UIApplication sharedApplication] openURL:phoneUrl];
} else {
UIAlertView * calert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Call facility is not available!!!" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[calert show];
}
}
关于ios - 可以给UILabel打电话吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22312792/