jjzjj

NBAsYouTypeFormatter

全部标签

ios - 如何在 iOS 中针对不同的区域代码实时格式化电话号码(使用 UITextfield 时)?

我找到了“NBAsYouTypeFormatter”并引用了提供的演示。但是,我希望当用户在UITextField中输入电话号码时动态格式化电话号码。请记住,在我的案例中,区域代码并不固定为一个或两个国家,例如仅@“US”或仅其他。区域代码将由用户从下拉列表中选择,所选代码将由我通过以下行传递:NBAsYouTypeFormatter*asYouTypeFormatter=[[NBAsYouTypeFormatteralloc]initWithRegionCode:@"US"];//maybeanyotherthan'US'NSString*output=[asYouTypeForma

ios - 使用 NBAsYouTypeFormatter 实时格式化电话号码

我到处搜索,看到了很多解决方案,但其中大部分确实是“hackish”且容易出错。我正在尝试使用libPhoneNumberiOS类NBAsYouTypeFormatter在UITextField上格式化电话号码。但是,我找不到合适的使用方法。下面是我的尝试。(来自这个线程Phonenumberformatios)varasYouTypeFormatter=NBAsYouTypeFormatter(regionCode:"US");functextField(textField:UITextField,shouldChangeCharactersInRangerange:NSRange,