A virus is a type of malware that works by spreading copies of itself to other pieces of code.
The iPhone operating system, iOS, is extremely locked-down. Most apps do not have the ability to modify the files containing other apps. So an infected app could not spread the infection to other apps. A "virus" that can't spread copies of itself isn't very much of a virus. Likewise, even if there was an infection, an anti-virus app couldn't remove it. An "anti-virus" app that can't disinfect or quarantine viruses isn't very much of an anti-virus app.
So when you see messages saying that your phone has viruses, those are generally scams. Lies meant to frighten you into installing useless "security" apps to solve non-existent problems … or worse, into contacting criminals who are posing as "tech support" so they can pretend to "help" you, while they collect the information that they need to help themselves to your money.
Could there be security issues in iOS? Yes. Could someone exploit them? Maybe. But many criminals these days find it easier to attack you (with "phishing" messages and the like) than to attack your phone. If they can trick you into giving them information they shouldn't have, or relaxing your own security, then it doesn't matter how secure your phone or computer is (or isn't).
Recognize and avoid social engineering schemes including phishing messages, phony support calls, and other scams - Apple Support