iOS 之拨号功能的实现

想要实现输入框中输入一个号码,点击按钮拨号的功能,很简单,让我们以纯代码的形式实现他。

首先,创建一个TextField 和一个UIButton

其次,写一个拨号的方法,与Button相关联

过程如下:

.h文件中


//

//  LYXViewController.h

//  UITap

//

//  Created by liyongxing on 13-7-6.

//  Copyright (c) 2013 liyongxing. All rights reserved.

//


#import <UIKit/UIKit.h>


@interface LYXViewController : UIViewController


@property (nonatomic,strong)UITextField * textFiled;


@property (nonatomic,strong)UIButton * button;



@end


//在.m文件中

//

//  LYXViewController.m

//  UITap

//

//  Created by liyongxing on 13-7-6.

//  Copyright (c) 2013 liyongxing. All rights reserved.

//


#import "LYXViewController.h"


@interface LYXViewController ()



@end


@implementation LYXViewController


-(void)viewDidLoad

{

    [super viewDidLoad];

    

    //创建一个输入框

    

    self.textFiled = [[UITextFieldalloc]initWithFrame:CGRectMake(505018040)];

    

    self.textFiled.backgroundColor = [UIColor grayColor];


    [self.view addSubview:self.textFiled];

    

    //创建一个按钮

    

    self.button = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    

    self.button.frame = CGRectMake(250,50 , 6040);

    

    [self.button addTarget:self action:@selector(PhoneButton)forControlEvents:UIControlEventTouchUpInside];

    

    [self.view addSubview:self.button];

    

    

    

    

}


//拨号的方法,就是定义一个字符串,如果字符串不等于空的情况下,那我们就打开一个拨号的路径,这个路径就是定义的字符串


-(void)PhoneButton

{


    NSString * phone = self.textFiled.text;

    

    if (phone != nil)

    {

        

        [[UIApplication sharedApplication]openURL:[NSURLURLWithString:[NSString stringWithFormat:@"%@",phone]]];

        

    }



}



- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值