下面的代码能在应用中添加一个电话按钮,点击即可拨打电话号码。对于 iPhone 开发者还是很有用的。  

//添加电话图标按钮
    UIButton *btnPhone = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
    btnPhone.frame = CGRectMake(280,10,30,30);
    UIImage *image = [UIImage imageNamed:@"phone.png"];    
    [btnPhone setBackgroundImage:image forState:UIControlStateNormal];
    
    //点击拨号按钮直接拨号
    [btnPhone addTarget:self action:@selector(callAction:event:) forControlEvents:UIControlEventTouchUpInside];

    [cell.contentView addSubview:btnPhone];  //cell是一个UITableViewCell

 

//定义点击拨号按钮时的操作
- (void)callAction:(id)sender event:(id)event{
    NSSet *touches = [event allTouches];
    UITouch *touch = [touches anyObject];
    CGPoint currentTouchPosition = [touch locationInView:self.listTable];
    NSIndexPath *indexPath = [self.listTable indexPathForRowAtPoint: currentTouchPosition];
    if (indexPath == nil) {
        return;
    }
    NSInteger  section = [indexPath section];
    NSUInteger  row = [indexPath row];
    NSDictionary *rowData = [datas objectAtIndex:row];

    NSString *num = [[NSString alloc] initWithFormat:@"tel://%@",number]; //number为号码字符串   
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:num]]; //拨号
}

相关文章:

  • 2022-12-23
  • 2021-09-02
  • 2022-12-23
  • 2022-02-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
  • 2021-12-07
  • 2022-02-20
  • 2022-12-23
相关资源
相似解决方案