gpt4 book ai didi

ios - 在ios中设置调用多个标签

转载 作者:行者123 更新时间:2023-12-01 17:17:29 26 4
gpt4 key购买 nike

我有一个电话号码变量agency.phone我有一个标签,该数字在 View 上显示 agencyPhone
我希望能够单击标签来调用号码,我找到了这段代码,但不确定如何在我的情况下实现它:

NSString *phoneNumber = [@"tel://" stringByAppendingString:mymobileNO.titleLabel.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];

感谢您帮助新手!

最佳答案

在 IB 中创建标签,然后将此代码添加到您的 .m 文件中

    - (void)viewDidLoad
{
[super viewDidLoad];

UITapGestureRecognizer* phone1LblGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(phone1LblTapped)];
// if labelView is not set userInteractionEnabled, you must do so
[agencyPhone setUserInteractionEnabled:YES];
[agencyPhone addGestureRecognizer:phone1LblGesture];
}

- (void)phone1LblTapped
{
UIDevice *device = [UIDevice currentDevice];
if ([[device model] isEqualToString:@"iPhone"] ) {
NSString *phoneNumber = [@"tel://" stringByAppendingString:agencyPhone.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
} else {
UIAlertView *Notpermitted=[[UIAlertView alloc] initWithTitle:@"Alert" message:@"Your device doesn't support this feature." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[Notpermitted show];
}
}

关于ios - 在ios中设置调用多个标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15296288/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com