How to change UI element image in script?

How can I change a UI’s image from a script? The only thing I’ve found is to load an image from resources as a sprite and change the sprite to that, but I can’t do that since my image is loaded from a URL over the web. So I have a texture, but can’t find a way to create a sprite from it.

you can create Sprite Objects run time using the Sprite.Create static method.
it is very simple and easy to use. once you have your texture of course.

var mySprite = Sprite.Create(myTexture, new Rect(0,0,256,256), new Vector2(128, 128));

myTexture is the texture you want to be used for the sprite.
new Rect(0,0,256,256) tells the method what part of the texture we want to use fore this sprite, this is useful for texture atlases, if you want to use the whole image just use 0 for the x and y axis and the respective image size values for width and height. In the case Above i assumed it was a 256x256 image.
new Vector2(128, 128) is the Pivot point of the sprite in pixels, for the centre , half of the respective image size relative the the Rectangle used for the sprite.

Hope it helps