The UV opacity of high-redshift galaxies