简体   繁体   English

快速将http://前缀添加到UITextField

[英]Add http:// prefix to UITextField in swift

If a user omits this prefix in browser the page will not load Anyone knows how to add http:// prefix to UITextField if user omits it? 如果用户在浏览器中省略了此前缀,则该页面将无法加载任何人都知道如果用户省略了如何将http://前缀添加到UITextField中? thanks 谢谢

i've checked the previous answers for objective-c solutions, and i thought to do it in the simple way: add the prefix if it's not there in the textfield, using "hasprefix": 我已经检查了先前针对Objective-C解决方案的答案,并且我想以一种简单的方式做到这一点:如果前缀在文本字段中不存在,则使用“ hasprefix”添加前缀:

 if(!textField.text!.hasPrefix("http://")){
       textField.text =  "http://" + textField.text!
    }

there's corner here which is https case, but this will fix the current situation. 这里是https的角落,但这将解决当前情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM