欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

OC 使用手机号获取验证码,添加国家编码

程序员文章站 2022-03-11 08:21:40
由于项目受众群里不是国内用户,所以在使用手机号获取验证码的时候需要添加国家编码。三行代码集成国家区号选择功能功能运行效果如图:国家代码 UI设置TextField的左paddingNSInteger m = 40;UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, m, 40)];self.textField.leftView = paddingView;self.textField.l...

由于项目受众群里不是国内用户,所以在使用手机号获取验证码的时候需要添加国家编码。

三行代码集成国家区号选择功能

功能运行效果如图:

OC 使用手机号获取验证码,添加国家编码

OC 使用手机号获取验证码,添加国家编码

国家代码 UI

设置TextField的左padding

NSInteger m = 40;
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, m, 40)];
self.textField.leftView = paddingView;
self.textField.leftViewMode = UITextFieldViewModeAlways;

然后将国家编码的按钮叠加在TextField上面就可以了。

 

国家代码开源链接: 国家编码

使用方法:

1.导入XWCountryCode类

2.在需要选择国家代码的事件中

XWCountryCodeController *CountryCodeVC = [[XWCountryCodeController alloc] init];
    //CountryCodeVC.deleagete = self;
    //block
    [CountryCodeVC toReturnCountryCode:^(NSString *countryCodeStr) {
    //在此处实现最终选择后的界面处理
    [self.countryCodeLB setText:countryCodeStr];
}];
[self presentViewController:CountryCodeVC animated:YES completion:nil];


 

本文地址:https://blog.csdn.net/shanghaibao123/article/details/107183061