1) Cutting spending elsewhere.
2) Raising taxes. (Or collecting more from a growing economy.)
3) Printing money.
Probably it would be a combination of all 3, but since UBI can offset entitlement cuts it makes sense to me that that's where the government would find a lot of the money. Raising taxes is unpopular and can be counterproductive if done to the extreme, and printing money is inflationary and also counterproductive unless there are other deflationary forces at work. (Which there are currently, I agree with Ray Dalio that printing money makes sense during a deleveraging spiral https://www.youtube.com/watch?v=PHe0bXAIuk0)
I'm not an advocate of replacing all means-based programmes with UBI, but it should see a significant improvement over many such.