简体   繁体   中英

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? 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":

 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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